#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    I currently have a datestamp in the format yyyymmdd. I want to pull the day of the week (Monday, Tuesday, etc...) out of that datestamp at any given time.

    Currently my code looks like this:
    $datearray = getdate($firstdatestamp);
    echo $datearray["weekday"];
    When $firstdatestamp = 20000501 (or the first of May, 2000) the weekday returned is Thursday when really it should be Monday!

    I tried:
    echo date("l", time());
    and it gives me the right weekday but only for the current date. I need to pass this my datestamp and am not too sure how.

    Please help!!!!!

    Thanks,
    Stephanie Lemaire
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Are you pulling this from a database? If so, many db engines have date functions that'll do that.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    8
    Rep Power
    0
    Yes actually, my data is coming from a MySQL database.

    I did figure out the reason it wasn't working was because my datestamp wasn't in proper UNIX format, so I develop a new datestamp out of the old one and process that.

    A cleaner way would be nice though

    Thanks,
    Stephanie
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    select dayname(date_field_name) as dayname from table;
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    15
    Rep Power
    0
    I would put the date into a unix timestamp when you pull it from the database. That way you can use the date function on it at any time to manipulate into the format you would like whether it be day of the week or whatever.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $result = mysql_query("SELECT UNIX_TIMESTAMP(my_date_field) FROM my_table");
    $row = mysql_fetch_array($result);
    $my_unix_date = $row["UNIX_TIMESTAMP"];
    $day_of_week = date("l", $my_unix_date);
    [/code]
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    7
    Rep Power
    0
    Dear Stephanie,

    If you want to pull day of the week out in any given time you can use built-in function from MySQL, ex:

    SELECT dayname("20000602");
    return value:
    +---------------------+
    | dayname("20000602") |
    +---------------------+
    | Friday |
    +---------------------+

    best regards,
    Tata

Similar Threads

  1. day of the week
    By ssaurabh in forum Java Help
    Replies: 2
    Last Post: January 29th, 2004, 07:47 AM
  2. Selecting days of week starting todays day
    By riotx in forum PHP Development
    Replies: 4
    Last Post: January 7th, 2004, 09:34 AM
  3. Replies: 1
    Last Post: January 6th, 2004, 06:19 PM
  4. date of the first day from a given week number
    By nickel in forum PHP Development
    Replies: 11
    Last Post: July 24th, 2003, 02:56 AM
  5. Getting day of the week from a date
    By craig34 in forum PHP Development
    Replies: 2
    Last Post: July 6th, 2003, 12:09 PM

IMN logo majestic logo threadwatch logo seochat tools logo