Re: Numbers to Date

From: Date: Fri, 16 May 2003 18:39:26 +0000
Subject: Re: Numbers to Date
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-147957@lists.php.net to get a copy of this message
How do I use what I have with the mktime() function? as a test, here's what I have: $Date = date("yz"); //Getting today's date in 5 digit format $Date = str_pad($Date, 5, "0", STR_PAD_RIGHT); //Stuffing any epty places $Year = substr("$Date", 0, 2); //Getting year $Day = substr("$Date", 2, 5); //Getting day of year $ReDate = mktime (0,0,0,0,$Day,$Year); //Making timestamp $TrueDate = date("l, F j, Y", $ReDate); //Putting in desired format print ("$TrueDate"); //Print the result Output: Monday, April 14, 2003 ... That's not right for today's date! "Kevin Stone" <kevin@helpelf.com> wrote in message news:002101c31bd7$4be0fb20$6500a8c0@kevin... > > ----- Original Message ----- > From: "zavaboy" <zavaboy@hotmail.com> > To: <php-general@lists.php.net> > Sent: Friday, May 16, 2003 11:53 AM > Subject: [PHP] Numbers to Date > > > > This does have a little to do with my other post... the fact that we're > > talkin about 5 digits... Anyway, I want to change a 5 digit number to a > full > > date: > > > > For example... > > > > The number: > > 03135 //(Today) The first 2 digits indacate the year > and > > the last 3 indacate the day of the year (if the day is 1 or 2 digits it > will > > fill in the blanks with 0 eg: 03500 is Jan 5) > > > > I want PHP to find out the date and put it in this format: "Friday, May > 16, > > 2003" (no quotes) ( as if I used: date("l, F j, Y") ) > > > > I'm stumped on how to do this... Any help? > > First use substr() to parse the values of the 5 number date into separate > variables. Then pass those variables to the mktime() function to retrieve a > timestamp for that date. Then pass the timestamp to the date() function > with your prefered format string. > > substr(); > http://www.php.net/manual/en/function.substr.php > > mktime(); > http://www.php.net/manual/en/function.mktime.php > > date(); // which of course you already know about. > http://www.php.net/manual/en/function.date.php > > HTH, > Kevin > >

« previous php.general (#147957) next »