HOW TO: convert a str date like Jan-05-03 16:38:48 PS, to a phpdate field? 
Author Message
 HOW TO: convert a str date like Jan-05-03 16:38:48 PS, to a phpdate field?

I'm trying to save a string date like:  Jan-05-03 16:38:48 PST
to a php date field.  strtodate() does not parse this format.

Any thoughts?

Thanks in advance...

Greg



Wed, 22 Jun 2005 02:04:12 GMT  
 HOW TO: convert a str date like Jan-05-03 16:38:48 PS, to a phpdate field?
Well, first of all the function you want is "strtotime()", not the one your
mentioned.  Even so, it's very easy to break up the input nicely:

If your string dates always look like that, simply explode until you get the
different bits into a workable format:

$input = "Jan-05-03 16:38:48 PST"

$temp = explode( " ", $input );

$date = explode( "-", $temp[0] );
// $date = array( 0 => Jan, 1 => 05, 2 => 03 );
$time = explode( ":", $temp[1] );
// $time = array( 0 => 16, 1 => 38, 2 => 48 );
$zone = $temp[2];
// $zone = "PST";

Now all the different parts are easily accessible.  Now you just pass them
to mktime() for the unix timestamp.  (Remember to convert "Jan"
appropriately and account for the timezone in your application logic)

-dlst


Quote:
> I'm trying to save a string date like:  Jan-05-03 16:38:48 PST
> to a php date field.  strtodate() does not parse this format.

> Any thoughts?

> Thanks in advance...

> Greg



Wed, 22 Jun 2005 13:46:16 GMT  
 HOW TO: convert a str date like Jan-05-03 16:38:48 PS, to a phpdate field?

Quote:

> I'm trying to save a string date like:  Jan-05-03 16:38:48 PST
> to a php date field.  strtodate() does not parse this format.

> Any thoughts?

First of all, you probably meant strtotime(), not strtodate(),
right?  :)

More to the point, replace dashes with spaces; strtotime() would
recoginze "Jan 05 03 16:38:48 PST" without a problem (at least it
does on my machine running PHP 4.0.6 under Linux)...

Cheers,
NC



Wed, 22 Jun 2005 13:54:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. sorting date-strings of form: Wed, 05 Jan 2000 10:07:02

2. comp.lang.modula2: Answers to Common Questions - v1.5 93.05.03

3. comp.lang.modula2: Answers to Common Questions - v1.4 93.05.05

4. new? string translate str str str

5. Converting date field in Clarion V2.1(DOS)

6. Converting integer to date field

7. Errors converting date fields to dbf

8. how to convert clarion date to sql date

9. How does STR know about fields?

10. Converting dates exported by CCVT to DBF dates

11. convert labview date/time to excel date/time

12. Problems when converting from QString to str

 

 
Powered by phpBB® Forum Software