Jump to content

Get current date and time.


GrayFox12

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/115323-get-current-date-and-time/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.