Date math rocks: What day of the year is today?

aztecconsultingaztecconsulting Member Posts: 55
I need to know which of the 365 (or 366) days of the year today is. I have searched for Julian Date but the one page I found with a formula is oftly complex. This conceptually should be east but I can't figure it out. Please help.

Comments

  • SavatageSavatage Member Posts: 7,142
    on http://www.mistupid.com/calendar/dayofyear.htm

    if you view-> source from your browser you can see the formula they use to calculate the number.

    maybe this can point you in the right direction.

    & you can use this if you want to create something like the web page
    http://www.mibuso.com/dlinfo.asp?FileID=518

    Here is a formula for finding the day of the week for ANY date.

    N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2
    read this:
    http://mathforum.org/library/drmath/view/55837.html

    You can always search google for
    "day number of the year formula"
    or
    "Julian Day Number Calculator"
  • SPost29SPost29 Member Posts: 148
    How about?
    DayOfYear(MyDate : Date) : Integer
      EVALUATE(FirstDay,'12/31/' + FORMAT((DATE2DMY(MyDate,3)-1)));
     //  -1 to get last day of previous year
     EXIT(MyDate - FirstDay);
    

    Works for leap years too.

    Steve
  • aztecconsultingaztecconsulting Member Posts: 55
    SPost29 wrote:
    How about?
    DayOfYear(MyDate : Date) : Integer
      EVALUATE(FirstDay,'12/31/' + FORMAT((DATE2DMY(MyDate,3)-1)));
     //  -1 to get last day of previous year
     EXIT(MyDate - FirstDay);
    

    Works for leap years too.

    Steve

    What's FirstDay? It's not a command I know of and the code doesn't work as is.
  • SPost29SPost29 Member Posts: 148
    Sorry for the confusion,
    FirstDay is a local Variable of datatype Date
    It could be called LastDay too, if that makes the code clearer
    Steve
  • aztecconsultingaztecconsulting Member Posts: 55
    With j1 as a boolean and jday as integer this worked like a champ!

    j1:=EVALUATE(FirstDay,'12/31/' + FORMAT((DATE2DMY(today,3)-1)));
    jday:=today-FirstDay;
  • girish.joshigirish.joshi Member Posts: 407
    There is another cleaner solution that uses built in Navision functionality.


    Format(today, 0, '<Weekday Text>')
  • SPost29SPost29 Member Posts: 148
    this function FORMAT(TODAY,0,'<weekday text>') returns the day name of the week, like Monday, Tuesday , etc. We were trying to find the day of the year like day 267 of 365.
    steve
  • girish.joshigirish.joshi Member Posts: 407
    oops, you're right... sorry, I should have read the posts more closely.
  • PureHeartPureHeart Member Posts: 190
    :-# :)
    Why don't you try my compare tool?
    http://www.mibuso.com/dlinfo.asp?FileID=1123
  • aohlfsenaohlfsen Member Posts: 30
    elapseddays:=TODAY-CALCDATE('<CY>',CALCDATE('<-1Y>',TODAY));
  • EugeneEugene Member Posts: 309
    even simpler solution:
    elapseddays:=TODAY-CALCDATE('<-CY>',TODAY)+1;
    
    here calcdate returns start of the year date (Jan 1st)
  • aohlfsenaohlfsen Member Posts: 30
    :D Nice
  • BeliasBelias Member Posts: 2,998
    :evil: :evil:
    Sorry, but I'm tired to think about this: I need to obtain the first and the last day of the next year, starting from a given date...
    e.g.: with 15/02/07 i need 01/01/08 and 31/12/08
    It's not a difficult problem, but I'm thinkin' and thinkin' the same thins and I won't get out of this hell alone... :evil: :evil:

    Thanks!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • BeliasBelias Member Posts: 2,998
    Wooohooo!!!
    GMAToDateCM :=  CALCDATE('<CY + 1Y>',ToDate);
    GMAFromDateCM :=  CALCDATE('<CY + 1Y + 1D - 1Y>',ToDate);
    

    This topic is an inspiration!!Thanks BTW
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • EugeneEugene Member Posts: 309
    Or like this:
    GMAToDateCM :=  CALCDATE('<CY + 1Y>',ToDate);
    
    GMAFromDateCM :=  CALCDATE('<-CY + 1Y>',ToDate);
    or
    GMAFromDateCM :=  CALCDATE('<CY + 1D>',ToDate);
    
  • BeliasBelias Member Posts: 2,998
    ME:
    GMAFromDateCM := CALCDATE('<CY + 1Y + 1D - 1Y>',ToDate);

    EUGENE
    GMAFromDateCM := CALCDATE('<CY + 1D>',ToDate);

    what's wrong in my code? if i want I can write
    GMAFromDateCM :=  CALCDATE('<CY + 1Y + 1M + 1D - 1Y - 1M + 8D - 8D>',ToDate);
    
    and that's right! #-o #-o #-o
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.