SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How does one define type for Date & Time and Insert it?

    Hi,

    What is the MySQL Type to use to define a field as being one that should store the date and time and not just date?
    And how does one insert that value?

    To be exact, one defines the MySQL Type for date to be: date
    And one inserts that value via NOW() in the insert statement.

    So how does one do the above for the value of date & time for the current date & time?

    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you look in the manual under DATE and TIME types?

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,834
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    For dates ( yyyy-mm-dd ) use date

    For times ( hh:mm:ss ) use time

    For both in one field ( yyyy-mm-dd hh:mm:ss ) use datetime

    For fields where you want the date and time set to when the record was first created without needing to assign it a value use timestamp
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think datetime is what we want since we want to stamp this field with the last date & time that they logged into their account.

    BTW, do you recommend to keep the date & time in separate fields or have the date & time in the same field using this datetime type? I know this is not a black and white question and one that is subjective.

    ThaNX


    Quote Originally Posted by felgall View Post
    For dates ( yyyy-mm-dd ) use date

    For times ( hh:mm:ss ) use time

    For both in one field ( yyyy-mm-dd hh:mm:ss ) use datetime

    For fields where you want the date and time set to when the record was first created without needing to assign it a value use timestamp

    Anoox search engine volunteer

    www.anoox.com

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,834
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by WorldNews View Post
    we want to stamp this field with the last date & time that they logged into their account.

    BTW, do you recommend to keep the date & time in separate fields or have the date & time in the same field using this datetime type?
    Since they only last logged in once, it makes sense to keep it in one field - you'd only consider two fields if there was at least some potential for date and time to need to be updated separately.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •