worldnews — 2011-08-21T01:18:28-04:00 — #1
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?
guelphdad — 2011-08-21T01:30:00-04:00 — #2
Did you look in the manual under DATE and TIME types?
felgall — 2011-08-21T02:18:46-04:00 — #3
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
worldnews — 2011-08-21T02:39:44-04:00 — #4
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.
felgall — 2011-08-21T02:52:51-04:00 — #5
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.