When I insert data into my MySQL database, a lot of the time I need to store the current datetime. I always want to store my datetimes as UTC time.
How do I store the current UTC time? Is there a built-in function or do I have to apply an offset to NOW()?
In MySQL you can use
UNIX_TIMESTAMP()which can provide all kinds of Date and Time Values and specific to your request you can useUTC_TIMESTAMP,UTC_TIMESTAMP()which returns the current UTC date and time as a value inYYYY-MM-DD HH:MM:SSorYYYYMMDDHHMMSS.uuuuuuformat, depending on whether the function is used in a string or numeric context.Example:
More Info is described here about MySQL Date/Time Functions:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp