Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Is there a native function for Weekday Name ??

    Is there an existing function to pass in either 0-6 or 1-7, and have it return the name of the weekday, or should I write a custom func? (I just don't want to recreate the wheel.)

    Example: I'd like to have echo func(2); print Tuesday.

    I double-checked both date() and getdate(), but obviously neither of those get the job done (unless you know something I don't ).

    Thanks-a-bunch.
    ~ Mo
    Last edited by mOrloff; 09-18-2010 at 10:49 PM.

  • #2
    New Coder
    Join Date
    Oct 2008
    Posts
    79
    Thanks
    0
    Thanked 7 Times in 7 Posts
    there is its on the date function

    D (capital) is 3 letter abbr eg mon tue wed
    l (lower L) is full name

    PHP Code:
    // Prints: July 1, 2000 is on a Saturday
    echo "July 1, 2000 is on a " date("l"mktime(000712000)); 
    http://php.net/manual/en/function.date.php

    look at the examples and format

    its all there

  • #3
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Yeah, but what about just passing in the day number ??

    In this existing loop I'm mod'ing, there is already a single-digit int value for day-of-the-week numbers.
    I don't want to have to create an entire date scenario just to get the day name .

    It'll take no time at all, so I think I'll just write the func.
    I just prefer to use existing tools (if they do in fact exist ) rather than create redundant functions.
    Last edited by mOrloff; 09-19-2010 at 01:22 AM.

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,301
    Thanks
    4
    Thanked 204 Times in 201 Posts
    PHP Code:
    function print_dow($daynum) {
    $daynames = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
    return 
    $daynames[$daynum];

    Use 0-6 with zero being Monday or rearrange the array any way you'd care to.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Thanks.
    That way is even simpler than what I did.

    Just for people who might hit this thread looking for answers in the future, I'd like to clarify.
    The 0-6 sequence usually designates Sunday-Saturday, while 1-7 usually designates Monday-Sunday (that is, at least, if you're silly like me and use the date() function as your benchmark ).

    This can EASILY be accommodated by including Sunday twice.
    Code:
    function dow($daynum) {
        $daynames = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
        return $daynames[$daynum];
    }
    If I missed anything, feel free to comment.
    Last edited by mOrloff; 09-20-2010 at 03:50 PM.

  • #6
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    to clarify, 'D' returns 'Mon' 'Tue' 'Wed', not 'mon' 'tue' 'wed' - please be precise if you offer advice


  •  

    Posting Permissions

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