How to replace Year of a DateTime variable with the Year of another DateTime variable in C#
While working in a project, I got stuck in the following issue :-
I have to compare the year of OldDateTime variable with NewDateTime variable. But if they both are not same
I have to replace the year of OldDateTime with the year of NewDateTime.
The solution which I got for this problem is as follows:-
DateTime OldDateTime ;
DateTime NewDateTime;
OldDateTime = (NewDateTime.Year == OldDateTime .Year) ? OldDateTime : new DateTime(NewDateTime.Year, OldDateTime .Month, OldDateTime .Day, OldDateTime .Hour, OldDateTime .Minute, OldDateTime .Second);
Hope it helps.....
0 Comment(s)