SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dow to Monday (etc) on 0-6 range - how

    HI,

    Just popping in from the mysql forum to find how to format my days of week.

    Yes I can use date::Calc but it uses to 1-7 range and I would prefer to use 0-6.

    what is best practice? would I have greater module options across all the date functions, if I used 1-7? If not, and I should use 0-6 would somone please tell me how to convert 0-6 to Monday,Tuesday,Wednesday,etc?

    bazz

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i know even less perl than php (if that's possible) so i don't know if there are any neater date functions (there probably are, eh), but here's an old reliable hack that works in any language that has a substring function
    Code:
    my $days = 'Sunday   Monday   Tuesday  WednesdayThursday Friday   Saturday Sunday   ';
    my $wkday =  substr $days, $dow*9, 9;
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Rudy,

    didn't know you hung about here too

    I'll check out your suggestion but this is what I cam up with since posting.

    Code:
    my @days_of_week = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
    
    my $formatted_day_end = $days_of_week[$day_end];
    bazz


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
  •