Solved

delphi DayOfYear

Posted on 2010-09-06
8
644 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Closing Comment

by:arwar49
ID: 33614978
ok
0
 
LVL 36

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 36

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now