Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Is a date on a weekend

Posted on 2007-10-11
5
Medium Priority
?
378 Views
Last Modified: 2010-04-05
I need to find out if a date I have selected from a datetimepicker is a saturday or sunday. How can i test a date for example; 14/10/2007.
0
Comment
Question by:ding-dong
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
rfwoolf earned 600 total points
ID: 20058859
Add DateUtils to the uses clause of your unit/form

Then this procedure will do it:

function DayOfTheWeek(const AValue: TDateTime): Word;

eg.
var
i: integer;
begin
i := DayOfTheWeek(14/10/2007);
if i = 6 then showmessage('Its a Saturday');
if i = 7 then showmessage('Its a Sunday');
end;

===

From the helpfile:

Call DayOfTheWeek to obtain the day of the week represented by a specified TDateTime value. DayOfTheWeek returns a value between 1 and 7, where 1 indicates Monday and 7 indicates Sunday.
 Note:
 DayOfTheWeek is ISO 8601 compliant (where Monday is considered the first day of the week). To obtain the day of the week where Sunday is considered the first day of the week, use the DayOfWeek function instead.
 
Tip:
 To make the return value more readable, use the Day of week constants.
 
0
 
LVL 1

Expert Comment

by:rambolivia
ID: 20058870
Hi ding-dong,

You can use the DayOfTheWeek function which returns the day of the week constants:

  DayMonday = 1;
  DayTuesday = 2;
  DayWednesday = 3;
  DayThursday = 4;
  DayFriday = 5;
  DaySaturday = 6;
  DaySunday = 7;

Good luck,

R.
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20058871
er, just to be clear in my previous post, when I said
function DayOfTheWeek(const AValue: TDateTime): Word;
--I didn't mean you should add that function to your unit -- that function is part of DateUtils -- you just call that procedure using that syntax.
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20058927
procedure TForm1.Button1Click(Sender: TObject);
var
X : Integer;
begin
// SplitStr('This is a test of this stuff', 4, ListBox1.Items);
X := DayofWeek(DateTimePicker1.DateTime);
If (X > 1) and (X < 7) then
 Edit1.text := 'This is a weekday'
  else
   Edit1.Text := 'This is a weekend';
end;
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20060519
WOOPS!

Had stuff in there from another post. Corrected...

procedure TForm1.Button1Click(Sender: TObject);
 var
 X : Integer;
begin
 X := DayofWeek(DateTimePicker1.DateTime);
 If (X > 1) and (X < 7) then
  Edit1.text := 'This is a weekday'
   else
    Edit1.Text := 'This is a weekend';
 end;
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

580 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