Solved

delphi DayOfYear

Posted on 2010-09-06
8
661 Views
Last Modified: 2013-11-22
i need to convert DayOfYear ---  eg. 249 to str 9/6/2010
0
Comment
Question by:arwar49
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:arwar49
ID: 33614900
this should be pretty straightforward - i just have a coder's block at the moment.
0
 

Author Comment

by:arwar49
ID: 33614909
i guess the 2010 is not part of DayOfYear - i said i had coder' s block

so i need function to convert 249 (DOY) to 9/6 (mo/day)
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33614940
Obviously you need the year, because 249 is different when it is a leap year and when not, right??
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 58

Accepted Solution

by:
cyberkiwi earned 50 total points
ID: 33614951
function DayOfYear(dayNum: integer; year: Word = 0): TDateTime;
var
  m,d: Word;
begin
  if year = 0 then
    DecodeDate(Now, year,m,d);
  Result := EncodeDate(year,1,1)-1+dayNum;
end;

ShowMessage(FormatDateTime('yyyy-mm-dd', DayOfYear(249)));
0
 

Author Closing Comment

by:arwar49
ID: 33614978
ok
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33615229
why not look in the DateUtils unit next time ?

There is the incday function which should be the easiest

Result := IncDay(EncodeDate(year, 1, 1), daynum-1);
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33621771
How is your line

Result := IncDay(EncodeDate(year, 1, 1), daynum-1);

different to my line

Result := EncodeDate(year,1,1)-1+dayNum;

which skips the function and uses floating point register directly.
The other content of the function is only to default to current year.

Unless there is some magic to IncDay that I am not aware of?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33624395
it is not different cyberkiwi,
i was more responding to forgetting things and having blackouts (usually monday morning)

the best to thing then is to look in those units for some unblocking ideas
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question