Drupal Dates in MySQL

Posted by gordon on Tue, 09/05/2006 - 10:21am

Drupal stores all dates in the unix time format which is the number of seconds since the 1/1/1970. This is good because adding days, it easy, just add 86400 seconds, or you can use the strtotime().

When you are trying to access data directly from the MySQL database because it is not stored in a date field, it just appears as a number.

However there is a trick you can use in MySQL which will display this number as a date. You can use the FROM_UNIXTIME() which will convert the unix time to a MySQL date. So you can do something like

SELECT n.nid, FROM_UNIXTIME(n.created) FROM node n

This will display the created field as a date field. These times will be displayed in GMT, so you will still need to adjust it to your local time.


kids cosrumes

Come here to choose kids costumes to participate in cosplay party. coserfans.com have many cosplay costumes. If you have kids like cosplay, Kids costumes 100% hand made to fit your body. Now Many children were wearing cosplay costumes girls costumes! Now Cosplay costumes are: kids costumes, girls costumes, toddler costumes. While not cosplay originated in Japan, but the United States are subject to the Japanese, particularly popular kids costumes. COS also to dream about his childhood, kids costumes!

This beautiful and

This beautiful and informative article, thank you very much. Use this page to your friend told you. I am constantly followed. To receive mp3 dinle more information about this topic the following internet sites can follow.

mp3 dinle muzik dinle

mp3 dinle muzik dinle

منتديات

Thanks for that, I always get date and time mixed up

Using MySQL date example

Adding/subtracting a day when storing in a MySQL datetime is easy too;

SELECT NOW()- INTERVAL 1 DAY;

You can get MySQL to work with timezones too;

mysql> select now();

+---------------------+
| now()               |
+---------------------+
| 2006-06-09 14:54:10 |
+---------------------+
1 row in set (0.00 sec)

(I am in GMT+10) 

mysql> set @@session.time_zone = '+00:00';
Query OK, 0 rows affected (0.00 sec)

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2006-06-09 04:54:32 |
+---------------------+
1 row in set (0.00 sec)

Typing Error?

I think you meant to type "SELECT n.nid, FROM_UNIXTIME(n.created) FROM node n" rather than "SELECT n.nid, FROM_UNIXDATE(n.created) FROM node n"

Thanks for that, I always

Thanks for that, I always get date and time mixed up. I think it was all those years programming in PICK which they used a DATE() to return the number of dates, instead of time() which returned number of seconds.

Well, not more of that, just good old PHP. 

Actually, not necessarily

Actually, not necessarily GMT, which is extremely annoying, but whatever MySQL thinks the timezone is. It's actually kind of annoying about that in that it's difficult (but not impossible) to tell MySQL to consistently give you GMT.