Re: Date format question
| From: | James, Yz | Date: | Mon, 15 Oct 2001 21:34:34 +0000 |
| Subject: | Re: Date format question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71142@lists.php.net to get a copy of this message | ||
Hi Don,
you need to use mktime() and maybe substr() to get the date split up into
the right variables to supply to mktime:
<?
function Mk14DaysFromNow($date) {
// Split the date up
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 7, 2);
// Make a timestamp to feed to date() later
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$date_we_want = $timestamp + (86400 * 14); // 86400 = seconds in a day
// Put the date into our format:
$display_date = date("m", $date_we_want) . "/" . date("d",
$date_we_want) . "/" date("Y", $date_we_want);
return $display_date;
}
echo Mk14DaysFromNow("20011015");
?>
http://www.php.net/substr
http://www.php.net/mktime
http://www.php.net/date
Hope that helps,
James
"Don" <don@lclcan.com> wrote in message
news:01cd01c155a7$b66bc4e0$c889cdcd@lclcan.com...
Hi,
I have a date string in the following format: yyyymmdd.
So today's date would show as 20011015
What I want to do is add 14 days to the date (month and year changes are
verified) and produce output that looks like, mmm-dd-yyyy as in: Oct-29-2001
(I know I can use the "date()" function to accomplish the latter.
Does anyone have a function that does the above?
Thanks,
Don