PHP Convert Date/Time to Day of Week

Posted on 2014-08-15
Last Modified: 2014-08-15
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.

Question by:dsg138
    LVL 30

    Accepted Solution

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

    Open in new window

    LVL 58

    Assisted Solution

    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


    Author Closing Comment

    These both worked great.  Thank you very much!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    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 how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now