4

How do I create a unix timestamp in MySQL? I know the type is set to INT and value is NULL but I need it to populate with current time in the format like: 1343782742

4
  • 3
    You really could have Googled this Commented Jan 23, 2013 at 14:22
  • I thought code help was for code help Commented Jan 23, 2013 at 14:26
  • 1
    Sure, if you show an effort. We're not here to do your work for you, though Commented Jan 23, 2013 at 14:26
  • 3
    clearly your not here to help anyone with negative post - sometimes when something is new to a person, they just need a little help... sorry to have bothered you. Commented Jan 23, 2013 at 14:31

1 Answer 1

8

use UNIX_TIMESTAMP(date)

SELECT UNIX_TIMESTAMP(NOW())
Sign up to request clarification or add additional context in comments.

8 Comments

Why use CURDATE() and not NOW()?
actually I want it to store it in the database in that format on record creation?
@JeffB the one I showed you was SELECT, you need to use INSERT, example, INSERT INTO tableName (colName) VALUES (UNIX_TIMESTAMP(NOW())) . you can add more columns and values if you want.
I think i'm asking my question wrong... I want the field within the database to auto pupulate with the current datetime when a record is inserted. I have a 'timestamp' field in th database, if i set the TYPE to DATETIME and DEFAULT to CURRENT_DATE that will work, but not in unix format.
I need the value stored in the DB as an INT not DATETIME in that format, I have hundreds of pages reading from that format in other DB i'm moving to new, so I need to keep in same format, where all new records get created with that field auto populating in unix datetime format.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.