Re: String datetime to DateTime

From: Date: Thu, 20 Jun 2002 15:48:20 +0000
Subject: Re: String datetime to DateTime
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-19909@lists.php.net to get a copy of this message
Thanks for the help, Mike. Trouble with sscanf... Incidentally I changed the $s in the format string to %s, I think that was a typo. :-) $str = "12/Jun/2002:01:02:26 -0600"; $newstr = sscanf($str,"%d/%s/%d:%d:%d:%d %s",$day,$mon,$year,$hour,$min,$sec,$offset); The trouble I'm having is with the first %s. It doesn't see the next delimiter so it puts the remaining text up to the next space into the $mon string. result: $day = 12 $mon = Jun/2002:01:02:26 other variables are empty Looking at php help online, there was a spanish user comment that seemed to be the same problem. And even though I can't read spanish, it looks like only a work around was suggested. I can work around this further but does anyone have a solution using sscanf? I'm not too clear on the acceptable syntax for the format string. Some comments intimate that I could use regular expressions withing there, but it doesn't seem to work either. Thanks in advance for any thoughts. Glenn <szii@sziisoft.com> wrote in message news:046401c217fb$56310b00$fd02a8c0@surfmetro.com... > DateTime formats are closer to what you have. > strtotime() will give you an unsigned integer(ususally long/32bit) for the > number of seconds since the unix epoch. > > Automagically from what you have to mySQL DateTime...nope...not that I can think of or find. > If you have the Unix timestamp in ulong format, you can use date() to put it in the correct format. > > Obvious workaround... > > MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. > The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. > > $str = "12/Jun/2002:01:02:26 -0600"; > $newstr = sscanf($str,"%d/%s/%d:%d:%d:%d $s",$day,$mon,$year,$hour,$min,$sec,$offset); > $newdatestr = <rebuild it here> > > I never noticed that it didn't store the GMT offset before. heh. > > 'Luck > > -Mike > > > ----- Original Message ----- > From: "Glenn Holden" <glenn@nilenet.com> > To: <php-db@lists.php.net> > Sent: Wednesday, June 19, 2002 3:58 PM > Subject: [PHP-DB] String datetime to DateTime > > > > Hello All! > > > > I have a unix time stamp in string format like this: > > > > 12/Jun/2002:01:02:26 -0600 > > > > I am trying to turn that back into a mySQL DateTime value. I've > > experimented with strtotime with no luck. I'm not really sure if that's > > what it's for. > > > > I can, of course, parse the string manually to build a datetime that MySQL > > will accept, but isn't there a function that handles this? > > > > How do -you- do this? > > > > Thanks! > > -Glenn > > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.db (#19909) next »