Jump to content

Local singapore time


sungpeng

Recommended Posts

date_default_timezone_set('Asia/Singapore');
$time=date('D,F j, Y, H:i:s A');
$insert_student=mysql_query("insert into listings (listdate) values ('$time')");

The setting for "listdate" field is datetime.

Can I know how what should I input "default" in mysql?

 

$time=date('D,F j, Y, H:i:s A');

Check also how to make it 24 hours. I find it difficult to insert into mysql the PM & AM if listdate setting is datetime default is 0000-00-00 00:00:00

Link to comment
https://forums.phpfreaks.com/topic/162515-local-singapore-time/#findComment-863404
Share on other sites

The format of a DATETIME field  is YYYY-MM-DD HH:MM:SS. There are two main reasons for that format -

 

1) The amount of storage used by a DATETIME has been optimized and it only takes 8 bytes. The format used by date('D,F j, Y, H:i:s A') takes around 31 bytes. This also means that queries involving a DATETIME value are optimized to execute as quick as possible.

2) Dates in the format YYYY-MM-DD can directly be sorted and compared.

 

You would produce values using date('Y-m-d H:i:s'). You can also set the timezone that the mysql server uses for your connection and use the mysql NOW() function in your query to give the same results. See the 'Per-connection time zones' section at this link - http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html

 

To format a DATETIME field when you SELECT it, use the mysql DATE_FORMAT() function - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

Link to comment
https://forums.phpfreaks.com/topic/162515-local-singapore-time/#findComment-863502
Share on other sites

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.