|
Hi, I have one datetime variable and when i click on datetime picker i want to compare both values as equal..
datetime variable is dt; datetimepicker1.value==dt; but it has seconds difference so can any one help me in this regard please..
thanks, Kumar.. kumar | | kumar449 Thursday, March 26, 2009 12:28 PM | If they have different seconds, they are different, but if you want to omit seconds in the comparison you should go for:
bool equal = dt.AddSeconds(-dt.Seconds) ==datetimepeicker1.value.AddSeconds(-datetimepeicker1.value.Seconds) - Marked As Answer byLinda LiuMSFT, ModeratorWednesday, April 01, 2009 3:53 AM
-
| | Christoph Wagner Friday, March 27, 2009 6:51 AM | Hi Kumar,
If you only want to compare the Year, Month and Day part of two DateTime value, you can opt to the following two methods except the way Christoph has suggested.
1. Construct new DateTime values based on the Year, Month and Day parts. For example:
DateTime dt = DateTime.Now;
DateTime dt1 = new DateTime(dt.Year, dt.Month, dt.Day);
DateTime dt2 = new DateTime(this.dateTimePicker1.Value.Year, this.dateTimePicker1.Value.Month, this.dateTimePicker1.Value.Day);
if (dt1 == dt2)
{
....
}
2. Compare the Year, Month and Day parts of the two DateTime values respectively. For example:
DateTime dt = DateTime.Now;
if (dt.Year == this.dateTimePicker1.Value.Year && dt.Month == this.dateTimePicker1.Value.Month && dt.Day == this.dateTimePicker1.Value.Day)
{
...
}
Hope this helps. - Marked As Answer byLinda LiuMSFT, ModeratorWednesday, April 01, 2009 3:53 AM
-
| | Linda Liu Tuesday, March 31, 2009 6:57 AM | If they have different seconds, they are different, but if you want to omit seconds in the comparison you should go for:
bool equal = dt.AddSeconds(-dt.Seconds) ==datetimepeicker1.value.AddSeconds(-datetimepeicker1.value.Seconds) - Marked As Answer byLinda LiuMSFT, ModeratorWednesday, April 01, 2009 3:53 AM
-
| | Christoph Wagner Friday, March 27, 2009 6:51 AM | Hi Kumar,
If you only want to compare the Year, Month and Day part of two DateTime value, you can opt to the following two methods except the way Christoph has suggested.
1. Construct new DateTime values based on the Year, Month and Day parts. For example:
DateTime dt = DateTime.Now;
DateTime dt1 = new DateTime(dt.Year, dt.Month, dt.Day);
DateTime dt2 = new DateTime(this.dateTimePicker1.Value.Year, this.dateTimePicker1.Value.Month, this.dateTimePicker1.Value.Day);
if (dt1 == dt2)
{
....
}
2. Compare the Year, Month and Day parts of the two DateTime values respectively. For example:
DateTime dt = DateTime.Now;
if (dt.Year == this.dateTimePicker1.Value.Year && dt.Month == this.dateTimePicker1.Value.Month && dt.Day == this.dateTimePicker1.Value.Day)
{
...
}
Hope this helps. - Marked As Answer byLinda LiuMSFT, ModeratorWednesday, April 01, 2009 3:53 AM
-
| | Linda Liu Tuesday, March 31, 2009 6:57 AM | Thanks for that and Sorry for the delay in reply... fine I understand..I need one more suggestion like how can i current day,month,year dynamically on respective day with out creating date object...Please do Help me in This.. kumar | | kumar449 Tuesday, April 21, 2009 5:15 PM | Thanks for that and Sorry for the delay in reply... fine I understand..I need one more suggestion like how can i current day,month,year dynamically on respective day with out creating date object...Please do Help me in This.. kumar | | kumar449 Tuesday, April 21, 2009 5:16 PM |
|