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 Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/ 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? Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224846 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 Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224859 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 Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224869 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? Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224871 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); ?> Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224872 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... Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224875 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); ?> Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224876 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 Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224878 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. Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224883 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 Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224886 Share on other sites More sharing options...
denhamd2 Posted April 9, 2007 Author Share Posted April 9, 2007 brilliant thanks guys Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224887 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] Link to comment https://forums.phpfreaks.com/topic/46246-solved-formatting-a-date-from-a-variable/#findComment-224898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.