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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.