[PHP] String to Date Conversion Problem
Hi, Guys: I am trying to turn a prepared line into a date format, and the string looks something like this: 23 JUL 09 - THURSDAY, and I am trying to change the string to a mm/dd/ format that looks like 07/23/2009. I tried to use strtotime() but it gave me nothing. Here is the code: list($date,$month,$year,$dash,$day) = split( ,$line,5); echo date2 . strtotime($date . \s . $month . \s . $year). /date2; Could anyone on the list please give me a hint on what I might have done wrong here? Thanks for your help. Alice _ All-in-one security and maintenance for your PC. Get a free 90-day trial! http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail
Re: [PHP] String to Date Conversion Problem
Hi Alice, Based on the string format that you mentioned (DD MMM YY - DAY) you should be able to transform to any other date using the following: $parts = explode(' ', '23 JUL 09 - THURSDAY'); echo date('m/d/Y', strtotime({$parts[1]} {$parts[0]} {$parts[2]})); Cheers Stuart On 31 Jul 2009, at 15:19, Alice Wei wrote: Hi, Guys: I am trying to turn a prepared line into a date format, and the string looks something like this: 23 JUL 09 - THURSDAY, and I am trying to change the string to a mm/dd/ format that looks like 07/23/2009. I tried to use strtotime() but it gave me nothing. Here is the code: list($date,$month,$year,$dash,$day) = split( ,$line,5); echo date2 . strtotime($date . \s . $month . \s . $year). /date2; Could anyone on the list please give me a hint on what I might have done wrong here? Thanks for your help. Alice _ All-in-one security and maintenance for your PC. Get a free 90-day trial! http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail smime.p7s Description: S/MIME cryptographic signature
RE: [PHP] String to Date Conversion Problem
Looks like what I did by using mm/dd/ was extra, which was probably why it didn't work. Thanks, looks like this is up and running now. Alice CC: php-general@lists.php.net From: stu...@stuconnolly.com To: aj...@alumni.iu.edu Subject: Re: [PHP] String to Date Conversion Problem Date: Fri, 31 Jul 2009 15:45:44 +0100 Hi Alice, Based on the string format that you mentioned (DD MMM YY - DAY) you should be able to transform to any other date using the following: $parts = explode(' ', '23 JUL 09 - THURSDAY'); echo date('m/d/Y', strtotime({$parts[1]} {$parts[0]} {$parts[2]})); Cheers Stuart On 31 Jul 2009, at 15:19, Alice Wei wrote: Hi, Guys: I am trying to turn a prepared line into a date format, and the string looks something like this: 23 JUL 09 - THURSDAY, and I am trying to change the string to a mm/dd/ format that looks like 07/23/2009. I tried to use strtotime() but it gave me nothing. Here is the code: list($date,$month,$year,$dash,$day) = split( ,$line,5); echo date2 . strtotime($date . \s . $month . \s . $year). /date2; Could anyone on the list please give me a hint on what I might have done wrong here? Thanks for your help. Alice _ All-in-one security and maintenance for your PC. Get a free 90-day trial! http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us