PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Day of the week finder Posted by jandrews on 29 Dec 2005 at 8:07 PM
I'm creating an online calendar for my faculty at my high school to use, but in order to properly display a given month, I need to know on what day of the week the first of the month falls. How do I query what day of the week a given date falls on? Thanks.

James
Report
Re: Day of the week finder Posted by tvienti on 2 Jan 2006 at 9:28 PM
Use the strtotime and date functions. I'm not sure if that's the most efficient way, but it would work.

strtotime let's to turn a string into a time represented as number of seconds since a fixed point. date accepts a number of seconds since the fixed point, and turns it into a string formatted however you want, according to the formatting string you input. So:

$seconds = strtotime('1 December, 2006');
$day = date('l', $seconds);


That will get you the day (Sunday - Saturday) that falls on the date 12/1/2006.

T

: I'm creating an online calendar for my faculty at my high school to use, but in order to properly display a given month, I need to know on what day of the week the first of the month falls. How do I query what day of the week a given date falls on? Thanks.
:
: James
:

Report
Re: Day of the week finder Posted by mac_doggie on 4 Jan 2006 at 3:14 AM
This message was edited by mac_doggie at 2006-1-4 3:14:50

or:
 // mktime parameters: 
 // hours, minutes, secods (don't need them so make them 0
 // then month, day, year
 // date("w") returns the day of the week 0 - 6 (0 beng sunday)
 $dayofweek = date("w", mktime(0,0,0,12,1,2006));



also see: http://nl2.php.net/manual/en/function.date.php
and: http://nl2.php.net/manual/en/function.mktime.php


: Use the strtotime and date functions. I'm not sure if that's the most efficient way, but it would work.
:
: strtotime let's to turn a string into a time represented as number of seconds since a fixed point. date accepts a number of seconds since the fixed point, and turns it into a string formatted however you want, according to the formatting string you input. So:
:
:
: $seconds = strtotime('1 December, 2006');
: $day = date('l', $seconds);
: 

:
: That will get you the day (Sunday - Saturday) that falls on the date 12/1/2006.
:
: T
:
: : I'm creating an online calendar for my faculty at my high school to use, but in order to properly display a given month, I need to know on what day of the week the first of the month falls. How do I query what day of the week a given date falls on? Thanks.
: :
: : James
: :
:
:


-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.