Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

date command

  • 11-11-2004 03:22PM
    #1
    Registered Users, Registered Users 2 Posts: 811 ✭✭✭


    I am trying to get week number from the date command using
    date +%W and the output is 45 but yet the week number 46

    Anyone got any glues what happening using redhat 9 ,Redhat 3 EL ,whitbox linux give all the same results
    thanks


Comments

  • Closed Accounts Posts: 820 ✭✭✭qBot


    Ya...it's doing the same on my machine..I'm guessing from what i've read in the man pages that week one is referred to as 0 and so on. Just increment whatever number u get from the program.
    %W   week number of year with Monday as first day of week (00..53)
    


  • Closed Accounts Posts: 286 ✭✭Kev


    The date command numbers the weeks starting from zero.
    Can you not just add one ?


  • Closed Accounts Posts: 95 ✭✭krinDar


    Rambo wrote:
    I am trying to get week number from the date command using
    date +%W and the output is 45 but yet the week number 46

    To get the value you want ( this being week 46) you could use the following:
    date +%V
    

    (works on Debian 3.0, Solaris 2.7 ... )

    I guess the behaviour of %W is the old method, starting the count
    from zero whereas %V is the behaviour defined by ISO 8601.


  • Registered Users, Registered Users 2 Posts: 811 ✭✭✭Rambo


    Kev wrote:
    The date command numbers the weeks starting from zero.
    Can you not just add one ?

    but when you reach week 53 it will be week 54 can do


  • Closed Accounts Posts: 820 ✭✭✭qBot


    Rambo wrote:
    but when you reach week 53 it will be week 54 can do

    If it does output 53 then it will still be infact week 54. I think there is 53 weeks in this year so the most date will go up to is 52. So 52 plus 1 is 53. Then it goes back to 1. However KrinDar seems to be right. The V option gives the correct output.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 811 ✭✭✭Rambo


    krinDar wrote:
    To get the value you want ( this being week 46) you could use the following:
    date +%V
    

    (works on Debian 3.0, Solaris 2.7 ... )

    I guess the behaviour of %W is the old method, starting the count
    from zero whereas %V is the behaviour defined by ISO 8601.

    look like you posted just before for the last post

    Thanks that works great


Advertisement