Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
When User choose Like this day 19-2-2016 is Friday and show message to the user tell him
this day is Friday and its Holiday

What I have tried:

i want this using datetimepicker in C#WinApp
Posted
Comments
BillWoodruff 17-Feb-16 9:06am    
If we do your homework, you will learn nothing. The fact you haven't really tried anything suggests this is homework.

"Holidays" ? Depends on what country you are in, doesn't it ? And, many types of holidays: holidays where banks are closed, holidays where banks are open, etc.

1) Define a class for holidays. E.g. starting-date, ending-date and name.
2) Define a class that holds all holiday-objects of 1) and offers methods to add a holiday and to check whether a certain date falls into some holiday. That method would then loop over all stored holidays and check for storedHoliday.StartingDate <= dateInQuestion <= storedHoliday.EndingDate and return true if it finds a hit, maybe optionally with the name of the holidays (e.g. as an out-parameter).
 
Share this answer
 
Try with below code:

Add ValueChanged event to DateTimePicker.
C#
this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);

Then add following code to handle ValueChanged event:
C#
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
        // Declare holiday list 
	string[] holidayList = { "03/01/2016", "02/20/2016", "02/17/2016" };

        // Check if selected value is holiday and display message
	if (holidayList.Contains(dateTimePicker1.Value.ToString("MM/dd/yyyy")))
	{
		MessageBox.Show("Selected date is holiday");
	}

    // Check if selected value is Friday then display message
    if (dateTimePicker1.Value.ToString("dddd") == "Friday")
    {
	  MessageBox.Show("Selected date is holiday");
    }
}
 
Share this answer
 
v9
try
C#
if (datetimepicker1.Value.ToString("ddd") == "Fri")
{
MessageBox.Show("Holiday");
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900