GrayFox12 Posted July 17, 2008 Share Posted July 17, 2008 Hi guys, im trying to get the current date and time to add to my mysql database. At the moment im doing it something like this: $date = date("d,m,y"); $time = time("g,i,a"); But i get completely random dates and times. Some of the dates come out as year 2010. How do i get it so i get the current date and time off the workstation or the server? Quote Link to comment Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 You can't get a clients time with php, only server time. The code you have seems fine are you sure you want the values comma seperated though? Quote Link to comment Share on other sites More sharing options...
GrayFox12 Posted July 17, 2008 Author Share Posted July 17, 2008 sorry their slash in their instead of comma. cant remember wat i put. So it could be server? Quote Link to comment Share on other sites More sharing options...
unkwntech Posted July 17, 2008 Share Posted July 17, 2008 With $date = date("d,m,y"); you should get the server date somthing like 17,07,08 however if you are getting values other then what is correct then there is a problem with the time at the server. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 18, 2008 Share Posted July 18, 2008 date("d,m,y") is not a mysql DATE or DATETIME format and attempting to put that into a DATE or DATETIME field will only work on rare occasions where the values in the fields happen to correspond to a real DATE or DATETIME value. time("g,i,a") is meaningless, because the time() function does not accept any parameters. You would either get an error or it would function, giving you a Unix Timestamp. To get the current server datetime, use the mysql NOW() function directly in your query. Quote Link to comment Share on other sites More sharing options...
j007ha Posted July 18, 2008 Share Posted July 18, 2008 try this : echo date('d-m-y h:i:s', time()); hope this can help Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 18, 2008 Share Posted July 18, 2008 You don't need a second parameter to the date() function if you want the current date/time. This: <?php echo date('Y-m-d h:i:s'); ?> will work just fine. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.