Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

delphi DayOfYear

Posted on 2010-09-06
8
Medium Priority
?
689 Views
Last Modified: 2013-11-22
i need to convert DayOfYear ---  eg. 249 to str 9/6/2010
0
Comment
Question by:arwar49
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress
Suggested Courses

715 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