...

View Full Version : storing the current date and time in mysql table



mrjameer
04-05-2007, 03:51 PM
hi,


i have a table called date_time.it has 2 fields.
field-name datatype
1.date date
2.time time

i want to store the current date and current time in that table.when ever i fetch the date and time it should display the current date and current time.any of your idea will be appreciated

thanks
mrjameer

Pennimus
04-05-2007, 04:26 PM
You use the date() (http://uk2.php.net/date) function to get both the date and time. There is no need to store this if you always want to retrieve the current date and time though - you just call it whenever you need it. If however you want to store the date and time at the time when the database record was updated, then simply assemble it in whatever format you want using the date() function and store it as normal.

mrjameer
04-05-2007, 05:06 PM
hi,




when a user will upload files on my site,the file info will be stored in table.and it will also shows a link to the user to download or visit that file.when he visits the link,the counter in table will be incremented.on every day at a particular time i want to update the counter to zero.that's all

thanks
mrjameer

nani_s23
05-03-2007, 01:29 PM
Hi friend,

usee.........just now() function in the insert table......it will work

for example.......

Insert into tablename (column1,column2,time.) VALUES ('$_post[columnname1]','$coulmnname2',now()).....

this works defiently....

whizard
05-04-2007, 12:11 AM
This query should do it for you:

$query = "INSERT INTO `date_time` (`date`,`time`) VALUES (DATE(),TIME())";

(enlarging on what nani_s23 said)

conversely, you could just have one field for the date AND time, and use the MySQL function NOW() to get the whole timestamp.

For more, check out http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_now

HTH
Dan

phpmonkey
05-04-2007, 12:25 AM
I have always used



putenv("TZ=EST5EDT"); // Eastern Time
//putenv("TZ=AST9ADT"); // Alaskan Time
//putenv("TZ=PST8PDT"); // Pacific Time
//putenv("TZ=MST7MDT"); // Mountain Time
//putenv("TZ=CST6CDT"); // Central Time
//putenv("TZ=GMT0"); // Greenwich Mean Time
//putenv("TZ=UTC0"); // Universal Time Coordinated


This is because normally, at least when I was learning PHP, time() only used the system time.

Using the putenv() function, time() reflects the time for the timezone you would like for it to use.

If this is wrong, someone please correct me.

PM

marf
05-04-2007, 03:09 AM
personally have always used now()

seems to work the best.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum