Solved

delphi DayOfYear

Posted on 2010-09-06
8
658 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Scripting vs. Programming languages 25 166
How to load 2 images in same column in Delphi 2 47
firemonkey keyboard covers the controls 1 26
SQL Insert parts by customer 12 34
A short article about a problem I had getting the GPS LocationListener working.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…

803 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