Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

Now i wanna to find some data between two dates depend upon current date. For example in my database i stored January(from) to March(to) is Winter(season), March to June is summer, June to September cold. Now i have one dateTimepicker and one Combobox. If am select july 18 means, Summer display at combobox, and feb 15 means it shows winter etc. how do this one... All replies are welcome...


Thanks & Regards

Dhinesh Kumar.V
Posted

in c#, calendar selectionchanged event
, check the selected date range and select the value in dropdown
C#
If (Calendar1.SelectedDate.Month>=1 &&Calendar1.SelectedDate.Month<=3)
dropdownlist.SelectedValue="Winter";
else If (Calendar1.SelectedDate.Month>=4 &&Calendar1.SelectedDate.Month<=6)
dropdownlist.SelectedValue="Summer"
else If (Calendar1.SelectedDate.Month&gt;=7 &amp;&amp;Calendar1.SelectedDate.Month&lt;=9)
dropdownlist.SelectedValue="Cold"

Updated solution:
So you meant to say you will decide the date and the season. So have a table with 3 columns SeasonName, StartDate, EndDate. Then whenever you select a value in calendar, query the name from this table.
SQL
Select seasonName from tbl where @dt between startdate and Enddate
 
Share this answer
 
v4
Comments
Dhinesh kumar.V 21-Sep-12 7:35am    
thanks for your reply santhosh. But here am using datetimepicker for select two dates and that seasons also update by me anytime...
Santhosh Kumar Jayaraman 21-Sep-12 7:43am    
So you meant to say you will decide the date and the season. So have a table with 3 columns SeasonName, StartDate, EndDate. Then whenever you select a value in calendar, query the name from this table.
Select seasonName from tbl where @dt between startdate and Enddate
Dhinesh kumar.V 21-Sep-12 8:06am    
why we use here @ santhosh.
Santhosh Kumar Jayaraman 21-Sep-12 8:08am    
its not just @, its @dt. thats my datetime variable which i will be passing in SQLCOMMAND. I believe you know about passign parameter to query in sqlcommand
Try this one
C#
//txt_date is textbox in which  you get the value from datatimepicker
//here the input in textbox named txt_date is in "mm/dd/yyyy" format
string[] date = txt_date.Text.Split('/');
string month = dd[0].ToString();
string date = dd[1].ToString();
string year = dd[2].ToString();
int m = Convert.ToInt32(month);


Now you get the month, Now get your season according to month;
C#
If (m>=1 || m<=3)
dropdownlist.SelectedValue="Winter";
else If (m>=4 || m=>6)
dropdownlist.SelectedValue="Summer";
else If (m>=7 || m<=9)
dropdownlist.SelectedValue="Cold";
 
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