Jump to content

[SOLVED] Formatting a date from a variable?


denhamd2

Recommended Posts

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

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

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

you're forgetting he wanted to print out the full name month to... ;D

 

<?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

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 ;D hope i didnt offend you ???

 

and denhamd2 .. dont forget to mark as SOLVED

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.