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


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?


Did you look in the manual under DATE and TIME types?

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


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.


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.