Jump to content


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


Date & Time Seperation

Recommended Posts


I have over 2000 records in the database for the site visitors. I was keeping the Time and Date in a field type "datetime" and the NOW() statement in php script was updating this field. So in all those records I have the time and date stored in "0000-00-00 00:00:00" format. Yes, I know this was a little stupid but I was new. Now I want to save Date and Time seperately in two different fields. I can do that for the new records but my question is that is it possible to split the past records too with one query without having to edit the fieilds one by one in a way that after executing the query all the records in "datetime" field get split and get stored in the same order into the two new fields for date and time?

I know this is not simple and am not really expecting an easy solution, although I have been getting perfect help from this forum.

Many Thanks in advance

[img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post

Link to post
Share on other sites
I want to also know how this can be done,

what do you do, would you extract all the old values then split them and then insert them via the users id dont no but very intresting.

Share this post

Link to post
Share on other sites
Why split them? My web app also uses that but there's no need to split the values when you can get the date and time from one value instead of two. Here's a function I use:[code]function datetostr($datetime)
        return gmdate("jS F Y", strtotime($datetime));

You could do the same to get any value like: date("d", strtotime($datetime)); to get the day. Just lookup the date() function and then you can use that to grab any value you want from the one stored in your database.

Share this post

Link to post
Share on other sites


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.