Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Days of the week
Wed, May 7 2014 1:02 PMPermanent Link

Matthew Jones

How can I output "Monday" for a date two days ago? Apologies for the wrapping here,
but the segment I want to improve is marked //HERE


function DateTimeToFriendly(tmDateTime : DateTime) : String;
var
   szDate : String;                      
   tmToday : DateTime;
begin      
   if DayOf(tmDateTime) = DayOf(Now) then
   begin
       szDate := 'Today';
   end
   else if DayOf(tmDateTime) = DayOf(JulToDate(DateToJul(tmToday) - 1)) then
   begin
       szDate := 'Yesterday';
   end
   else if DayOf(tmDateTime) > DayOf(JulToDate(DateToJul(tmToday) - 6)) then
   begin
       // HERE
       szDate := DateToStr(tmDateTime);
   end
   else
   begin
       szDate := DateToStr(tmDateTime);
   end;
   Result := szDate;
end;

I can see that EWB has the TFormatSettings and that has the days of the week in
long form, but I can't see how to work that out. DayOf is the date of the month,
not the day of the week. I'm too used to libraries for this!

/Matthew Jones/
Wed, May 7 2014 2:00 PMPermanent Link

Malcolm Taylor

Hi Matthew

I think you are looking for WeekDayOf()

Malcolm
Thu, May 8 2014 6:12 AMPermanent Link

Matthew Jones

Thank you!

   szDate := FormatSettings.LongDayNames[WeekDayOf(tmDateTime)];

Works fine.

/Matthew Jones/
Image