1

I am using .Net 4.0. I am working on an application which was first meant for USA only but now its getting global. Issue is: All calculations done in USA or other country happens to be in their individual time zone. Now when we want to compare or filter some data based on a particular date then they dont match as time part of the whole date is different. I know we cant implement application wide timezone like a Culture thing. But is there a way to make minimal code changes and compare only Date part of the DateTime properties in the whole application.

Date which was saved in USA timezone comes as below when India user checks them:

23-Oct-2014 09:30:00 AM

Now when a India user wants to filter 23-Oct-2014 data, nothing is returned because:

23-Oct-2014 09:30:00 AM is not equal to 23-Oct-2014 12:00:00 AM

I dont want to make change in thousands for DateTime properties in whole application, Is there a way to correct the issue with minimal code change for whole application. Any help is greatly appreciated.

Navneet Duggal
  • 91
  • 1
  • 15
  • possible duplicate of [How to compare only Date without Time in DateTime types in C#?](http://stackoverflow.com/questions/683037/how-to-compare-only-date-without-time-in-datetime-types-in-c) – eddie_cat Sep 26 '14 at 20:11
  • I am hoping to get a solution with minimal code change. the solution provide in this link requires making code change in each and every DateTime comparison in the whole application. – Navneet Duggal Sep 26 '14 at 20:15
  • 1
    Ctrl+F? I'm not sure how you expect the code to suddenly start acting different if you don't change it... – eddie_cat Sep 26 '14 at 20:19
  • 1
    @NavneetDuggal Your problem does not depend on application users being in different time zones. If you, in India, save a file at 23-Oct-2014 09:30:00 AM local time, and then you, in India, search for files saved on 23-Oct-2014 by looking for the value 23-Oct-2014 12:00:00 AM, you're still not going to find the file. – phoog Sep 26 '14 at 20:22
  • Unless you actually saved the datetimes as (converted/formatted) strings - setting correct culture on the thread sounds like a way to go for displaying the datetime. – Allan S. Hansen Sep 26 '14 at 20:52
  • I dont think there is any other solution other than a Hack or return a .Date in getter of each DateTime property in my application. – Navneet Duggal Sep 29 '14 at 15:37

1 Answers1

2

This may sound crazy, and I don't know if this will work with all of your code. Especially if you have 3rd party libraries

but if you add a structure to the project under the System namespace and name it DateTime then it will override the real System.DateTime and it's use will have the swiggly underlines with a message saying it conflicts with the original and is using yours.

I don't think this is a great idea but if you copy the datetime code and change what you need it just might work.

DateTime.cs

class program

RadioSpace
  • 953
  • 7
  • 15