943,910 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 522
  • PHP RSS
Apr 26th, 2009
0

Date Conversion

Expand Post »
In a code routine I receive strings like “04242009” and I need to convert it to April 24, 2009. I have played with several of the date conversion routines but I am getting no where. Help would be appreciated.

Thanks!
WBR
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster
rouse is offline Offline
111 posts
since Dec 2007
Apr 27th, 2009
0

Re: Date Conversion

apply substring function
PHP Syntax (Toggle Plain Text)
  1. $day=substr("04242009", 0, 1);
  2. $month=substr("04242009", 2, 3);
  3. $year=substr("04242009", 4, 7);
  4. $mydate=$year."-".$month."-".$day;
  5.  
  6. $converted_date=date($mydate,'F d, Y');
Last edited by BzzBee; Apr 27th, 2009 at 2:14 am.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 27th, 2009
0

Re: Date Conversion

Thanks for pointing me in the right directions. I had to make some changes to your code and this is what I finally ended up with.
WBR
PHP Syntax (Toggle Plain Text)
  1. $chopDate =” 04242009";
  2. $month=substr($chopDate, 0, 2);
  3. $day=substr($chopDate, 2, 2);
  4. $year=substr($chopDate, 4, 7);
  5. $myDate=$month . "/" . $day . "/" . $year;
  6. $printDate = date("jS F, Y", strtotime ($myDate));
  7. print ("<h3> <center>$printDate </center></h3>");
  8.  
Reputation Points: 10
Solved Threads: 1
Junior Poster
rouse is offline Offline
111 posts
since Dec 2007
Apr 27th, 2009
1

Re: Date Conversion

it depends on your requirement. i didn't knew your requirement so i just gave an idea with dummy example.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How To Create A Free Web Host
Next Thread in PHP Forum Timeline: XML to PHP Help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC