Jump to content


Date & Time Seperation

  • Please log in to reply
2 replies to this topic

#1 koolgirl

  • Members
  • PipPip
  • Member
  • 17 posts

Posted 17 June 2006 - 06:12 PM


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\" /]

#2 redarrow

  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 June 2006 - 06:20 PM

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.

Wish i new all about php DAM i will have to learn

#3 Fyorl

  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 11:18 PM

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

Don't worry, the printer fairies will sort it out.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users