display weekend dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

display weekend dates

Post by keithh0427 »

A newbie question.

I'm trying to display the Friday-Sunday dates at the top of a report and I only have Friday in the database as Y-m-d.

The format I'm attempting to get is "Dec 24-26, 2004". I can get "Dec 24, 2004" OK, but when I use mktime() I can't figure out how to get only the day from that date into the text I'm looking for.

Any help would be greatly appreciated.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

have you visited [php_man]date[/php_man]??
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

Post by keithh0427 »

yes. I'm trying to figure it out and having trouble. that's why I posted here. I'm still working on it.

$weekendSun= mktime(0, 0, 0, $weekendFri("m") , $weekendFri("d")+2, $weekendFri("Y"));

Just having trouble displaying in the correct format.
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

Post by keithh0427 »

Got it figured out.

Code: Select all

$date_input = $weekendDate_selected;
     list($year, $month, $day) = split('ї/.-]', $date_input);
$weekendDate_selected = $month . "-" . $day . "-" . $year;

$weekendFri=date("M-d-Y", mktime(0, 0, 0, $month, $day, $year));

$date_input=date("M-d-Y", mktime(0, 0, 0, $month, $day+2, $year));
     list($month2, $day2, $year2) = split('ї/.-]', $date_input);
$weekendSun = $month2 . "-" . $day2 . "-" . $year2;

echo "<font face=arial size=5><center>Worldwide Marriage Encounter</center></font>";
echo "<font face=arial size=3><center>Weekend List</center></font>";
echo "<font face=arial size=3><center>for: ", $month2, " ", $day, "-", $day2, ", ", $year, "</center></font>";
Thanks
kenrbnsn
Forum Newbie
Posts: 13
Joined: Tue Jul 01, 2003 3:34 pm
Location: Hillsborough, NJ USA

Post by kenrbnsn »

Take a look at the following code:

Code: Select all

<?
$fri = date('M j, Y',strtotime('this friday'));
$sun = date('M j, Y',strtotime($fri . ' +2 days'));
echo 'Friday: ' . $fri . "<br>\n";
echo 'Sunday: ' . $sun . "<br>\n";
?>
I know some people frown on using the strtotime function, but I like it since it will translate an (almost) english phrase to a date/time.

This code segment should help you find a solution to your problem.

Ken
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

Post by keithh0427 »

Thanks! I like that solution better than the one I worked on.
Post Reply