[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4999
  • Last Modified:

PHP Convert Date/Time to Day of Week

Experts, I'm adding sports data to my Database from an XML Feed.

One of the important items is the event-date-time.  Here is an example:
<event-metadata event-status="" league="NFL Football" event-date-time="09/04/2014 08:30 PM"/>

$game_time = "09/04/2014 08:30 PM";
I add "09/04/2014 08:30 PM" to my database for this event.
This part works fine today.

Here is my question:
I'm now trying to also add the "Day of the Week"  to my database.
So something like this automatically calculating: $game_day = "Thursday";

In the example above, I'm trying to automatically get the "Thursday", or even "5" from the value in $game_time.

Any help would be great.

2 Solutions
Marco GasiFreelancerCommented:
You can try this (untested):
$timestamp = strtotime($game_time);
$dw = date( "w", $timestamp);

Open in new window

Correction to Marco's example - w is for the weekday number

For the short day Mon,Tue etc
$timestamp= strtotime($game_time);
date( "D", $timestamp);

Open in new window

For the full day e.g. Monday, Tuesday
$timestamp= strtotime($game_time);
date( "l", $timestamp);

Open in new window

dsg138Author Commented:
These both worked great.  Thank you very much!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now