1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

What Day of the Week Does it Fall on?

Find out what day of the week a specified date falls on

By

While some holidays (Easter for example) always fall on the same day of the week, others vary every year. If you want to find out what day of the week Halloween, Christmas, or even your birthday falls on, you can use PHP!

The first thing you need to do is use the mktime() function to create a timestamp for the day in question. In our example we will use Halloween.

$h = mktime(0, 0, 0, 10, 31, 2008);

Next you can format this date in different ways using standard date formatting:

$d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;

Finally you tell the user what day of the week their event falls on simply using Echo():

Echo "$d is on a $w";

So the full code will look like this:

<?php
 $h = mktime(0, 0, 0, 10, 31, 2008);
 $d = date("F dS, Y", $h) ;
 $w= date("l", $h) ;
 Echo "$d is on a $w";
 ?>

The code above will return: October 31st, 2008 is on a Friday

  1. About.com
  2. Technology
  3. PHP / MySQL
  4. Step By Steps
  5. PHP Script to Determine a Given Date's Day of the Week

©2014 About.com. All rights reserved.