Thanks for the help
I'm fairly certain a fancy preg_replace could do it all at once...
(if you sit down and write it some late night, please share...)
I didn't use the exact functions you suggested, not sure what the difference
is (yet).
Here's what I ended up with, it could easily be turned into a function:
Glenn
// get date string from between square brackets
if (preg_match('/\[.*\]/',$RawLine,$M)) {
// parse date: [19/Jun/2002:00:13:13 -0600]
$tm = substr($M[0],1,26); // remove brackets
$tm = preg_replace('/\x2F|\x3A/',' ',$tm); // replace '/' and ':' with ' '
$MonthStrings = array('/Jan/','/Feb/','/Mar/','/Apr/','/May/','/Jun/',
'/Jul/','/Aug/','/Sep/','/Oct/','/Nov/','/Dec/');
$MonthNumbers = array('01','02','03','04','05','06',
'07','08','09','10','11','12');
$tm = preg_replace($MonthStrings,$MonthNumbers,$tm); // replace Month
Strings with Month Numbers
$a = sscanf($tm,"%d %s %d %d %d %d
%s",&$day,&$mon,&$year,&$hour,&$min,&$sec,&$offset);
$tm = $year.'-'.$mon.'-'.$day.' '.$hour.':'.$min.':'.$sec; // reorganize
unix date time to mySql date time
echo "DateTime: ".$tm.""; // produces=> DateTime: 2002-06-19 0:13:13
}
<[EMAIL PROTECTED]> wrote in message
097901c2188f$a2628230$[EMAIL PROTECTED]">news:097901c2188f$a2628230$[EMAIL PROTECTED]...
> Hmm...odd. I guess their %s (yes that was a typo) looks for a space
> as a delimiter and not the specified next one.
>
> Easiest workarounds off the cuff...
> 1) sscanf() to get the bulk of the data out, then regex out the %s
string.
> 2) eregi_replace() Jun with the numeric
> 3) Dump it as numeric instead of a string month name
> 4) eregi_replace() the /'s with spaces then sscanf() it.
>
> 'Luck
>
> -Mike
>
> - Original Message -
> From: "Glenn Holden" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, June 20, 2002 8:48 AM
> Subject: Re: [PHP-DB] String datetime to DateTime
>
>
> > 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
> >
> >
> >
> >
> > <[EMAIL PROTECTED]> wrote in message
> > news:046401c217fb$56310b00$[EMAIL PROTECTED]...
> > > 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 '-MM-DD HH:MM:SS'
> > format.
> > > The supported range is '1000-01-01 00:00:00' to '-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 =
> > >
> > > I never noticed that it didn't store the GMT offset befor