Jump to content

Simple timedate problem


bugzy

Recommended Posts

Ok I got this column "date_reg" on my table which has a "datetime" type.

 

It's giving me a value like "2012-04-20 04:28:03"

 

The problem is, when I'm trying to insert on that column using this format

 

<?php $datenow = date('m/d/Y h:i:s a', time()); ?>

 

it's giving me a value of "0000-00-00 00:00:00" which is suppose to be the current date and time the user add on that table.

 

 

Anyone knows how I can fix this?

Link to comment
https://forums.phpfreaks.com/topic/261390-simple-timedate-problem/
Share on other sites

The DATETIME column is limited to YYYY-MM-DD HH:MM:SS format.  Anything else is illegal.

 

Simply insert it that way, then format it as you desire when showing it to the user.

 

You can also store it as a unix timestamp and format it as well.  Many people find a unix timestamp to be easier to work with when doing advanced mathematics.

The DATETIME column is limited to YYYY-MM-DD HH:MM:SS format.  Anything else is illegal.

 

Simply insert it that way, then format it as you desire when showing it to the user.

 

You can also store it as a unix timestamp and format it as well.  Many people find a unix timestamp to be easier to work with when doing advanced mathematics.

Yes, unix timestamp is nice, but both is stored the same way and handled almost the same way. Though I think too a unix timestamp is easier to work with, but it's not as easy to look at with the human eye in the database. You can make the DATETIME return unix time by using UNIX_TIMESTAMP().

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.