SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast amherst's Avatar
    Join Date
    Jul 2003
    Location
    London UK
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Finding day of week from MySql date

    I'm sure there's an easy way to do this but I haven 't worked it out yet. I am trying to produce a forthcoming events list from a MySql database.

    The date is stored in YYYY-MM-DD format, as I found this was the easiest way to sort the rows by date (maybe I'm wrong about that). What I need to do is to specify the day of the week in words - Mon, Tue etc (the client has asked for that). I know how to do it with today's date - but can't work out how to find out how to do it with dates in the future.

    I've just entered a few rows of test data so far - and I could easily change the database structure to format the date field in some other way so if it would be easier that way, please let me know.

    Mike

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http://en.wikipedia.org/wiki/Calcula...ay_of_the_week

    There are algorithms available for working it out, try google if the above doesn't help.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If i have understood what you want to do, since you can convert the date taken from the database with PHP, you can display your date in whatever format you want.
    PHP Code:
    // Lets suppose this your date taken from database
    $date "2007-11-27";
    // now you can format it as you want.
    echo date('D, M d, Y',strtotime("$date")); 
    This will output :
    Code:
    Tue, Nov 27, 2007
    Umm, I don't know whether i got what you mean or not.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Stormrider View Post
    http://en.wikipedia.org/wiki/Calcula...ay_of_the_week

    There are algorithms available for working it out, try google if the above doesn't help.
    No need to implement your own algorithm, since both MySQL and PHP (as rajug rightly pointed out) already have everything you need to get what you want.

  6. #6
    SitePoint Enthusiast amherst's Avatar
    Join Date
    Jul 2003
    Location
    London UK
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to everyone for helping - especially rajug. Don't think my brain was in gear when I was looking at this problem yesterday.

    Long time since I've visited Sitepoint. As useful as ever!
    Best regards to all
    Mike


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •