denhamd2 Posted April 9, 2007 Share Posted April 9, 2007 hi, I have the date in the format 01012007 stored in the variable $mydate is there any way I can echo this in the format Monday, 1st January 2007? I was told using mkdir get timestamp for this 01012007 Then use date function to change date format... I'm a bit of a newbie so would anyone know how to do this? Thanks in advance Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 mkdir? are you making a folder on your server with that name? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 9, 2007 Share Posted April 9, 2007 um, is is a string, or a timestamp or what??? if string, then look at the string sormatting functions, look for one that will slice the string at every "x" characters. then simply format from the array output, if timestamp, then go $new_date = date("FORMATING STRING HERE") um, look at "date formatting" in tutorials good luck Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 i think you should go for using substr() and the date() and mktime() maybe to get the info about named months like january, february etc... here's a something quick i made that you can use as a guideline.. <?php $string = "01012007"; $month = substr($string, 0, 2); $day = substr($string, 2, 2); $year = substr($string, 4, 7); ?> to find out more go to: http://us2.php.net/manual/en/function.substr.php http://us2.php.net/manual/en/function.date.php http://us2.php.net/manual/en/function.mktime.phpr Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 9, 2007 Author Share Posted April 9, 2007 its stored as a string. going on clown[NOR]'s post above how would I then format the date as Tuesday, January 1st 2007? Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 9, 2007 Share Posted April 9, 2007 <?php $string = "01012007"; $month = substr($string, 0, 2); $day = substr($string, 2, 2); $year = substr($string, 4, 7); $timestamp = mktime(0,0,0,$month,$day,$year); $formateddate = date("l, jS Y" ,$timestamp); ?> Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 but what I found out doing that was that 01 = December..haha... Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 9, 2007 Share Posted April 9, 2007 <?php $string = "01012007"; $month = substr($string, 0, 2); $day = substr($string, 2, 2); $year = substr($string, 4, 7); $timestamp = mktime(0,0,0,$month,$day,$year); $formateddate = date("l, jS Y" ,$timestamp); ?> Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 you're forgetting he wanted to print out the full name month to... <?php $string = "01012007"; $month = substr($string, 0, 2); $day = substr($string, 2, 2); $year = substr($string, 4, 7); $timestamp = mktime(0,0,0,$month,$day,$year); $formateddate = date("l, F jS Y" ,$timestamp); echo $formateddate; ?> prints out: Monday, January 1st 2007 Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 9, 2007 Share Posted April 9, 2007 Ok clown[NOR] This is just to give idea to denhamd2. Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 9, 2007 Share Posted April 9, 2007 yeah... i was just so happy... someone actually asked about something that I knew and didnt have to look up first..hehe... got a lil carried away... sorry jitesh hope i didnt offend you ??? and denhamd2 .. dont forget to mark as SOLVED Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 9, 2007 Author Share Posted April 9, 2007 brilliant thanks guys Quote Link to comment Share on other sites More sharing options...
denhamd2 Posted April 9, 2007 Author Share Posted April 9, 2007 bit of a problem, its taking 25042007 and formatting it as Sunday, January 4th 2009... any ideas as to why this could be? EDIT: sorted this now - i had to change month, day, year to day, month, year [european style date formatting] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.