View Full Version : mySQL timestamps
Weirfire
Oct 22nd 2004, 9:30 am
When you have a variable in a mySQL database which is of the timestamp format do you have to assign a value to the timestamp or does it do it automatically?
digitalpoint
Oct 22nd 2004, 9:35 am
It's a number... so just use an integer.
Weirfire
Oct 22nd 2004, 9:39 am
So would you recommend storing the date as a timestamp? :confused:
digitalpoint
Oct 22nd 2004, 9:42 am
Depends on if you need the time or not. If you just need the date (and not time), then it's not necessary. If you want both date and time, it's a good format.
Weirfire
Oct 22nd 2004, 9:43 am
Yes I need the time. :)
Thanks Shawn.
mushroom
Oct 22nd 2004, 12:21 pm
Yes I need the time. :)
Thanks Shawn.
The first timestamp that is in a table is set to now(); on every insert or update automaticly even if you do not mention it.
Reads or updates that make no changes to the row leave the timestamp unchanged.
Weirfire
Oct 23rd 2004, 1:07 am
Thanks for your help Mushroom.
I've got it going now :D
Ozz
Oct 25th 2004, 10:26 pm
Use datetime instead... timestamp is terrible. As Mushroom said timestamp is updated automatically unless you declare the value in the query... if you forget its going to be a disaster... specially if you want to create logs or statistics... lets say that you missed this detail in the query and an entire set of rows goes withthe wrong data (it happened to me once... lucky me I backed up the database before :D).
In fact as I remember MySQL is going to change the way timestamps behave soon (in v4.1 or 5)... so again... its better to use datetime for me.
aspcoder
Dec 3rd 2004, 4:12 am
If you use MySQL timestamp, you must use MySQL function date_format() in the MySQL select command.like a ,
select date_format(now(),'%d-%m-%Y');
and you can replace the now() function with any column with timestamp type.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.