Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

date command

  • 11-11-2004 2: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: 96 ✭✭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