Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

delphi DayOfYear

Posted on 2010-09-06
8
Medium Priority
?
697 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 58

Accepted Solution

by:
cyberkiwi earned 200 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 38

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 38

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Six Sigma Control Plans
Starting up a Project

886 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