php date manipulation

Posted on 2013-09-18
Medium Priority
Last Modified: 2013-09-18
I am using the php date() function to add days to current date and store that into a variable and then later access the variable and return what day of the week that date falls on. But my code keeps returning Thursday regardless of the date used.

The code I'm using is as follows:

  echo $wd = date("d/m/Y", strtotime("+3 days"));
  echo "<br><br>";
  echo date("D",strtotime($wd));

Open in new window

Question by:ACEAFTY
  • 2
LVL 62

Accepted Solution

Julian Hansen earned 2000 total points
ID: 39502239
Try formating your date as "d-m-Y"

Because of the ambiguities with YMD and YDM for dates where day and month are < 12 PHP uses the / and hyphen characters to help determine which format is being used.

You are using dmy i.e. month in the middle so use '-' to delimite your date parts

This should work
  echo $wd = date("d-m-Y", strtotime("+3 days"));
  echo "<br><br>";
  echo date("D",strtotime($wd));

Open in new window


Author Closing Comment

ID: 39502431
Thanks that helped.
LVL 62

Expert Comment

by:Julian Hansen
ID: 39502530
You are welcome - thanks for the points.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question