Jump to content

Date & Time Seperation


koolgirl

Recommended Posts

Hi,

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\" /]
Link to comment
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));
    }[/code]

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