1

I have a C# Web application which has been installed in the US Server and database is in another server. I am accessing my application from India. Now when user sign up, he choose the Reporting date from the calender control which has the current system date time selected by default and User Creation date is inserted from the background C# code. Since I am using the application in my local country browser, that's why both the dates are different. Is there anyway to resolve this conflicts.

obUser.CreationDate = Datetime.Now
Steve
  • 213,761
  • 22
  • 232
  • 286
Pankaj Saha
  • 869
  • 3
  • 17
  • 37
  • 1
    Can you explain with example and what is your problem as such ? – V4Vendetta Apr 25 '13 at 09:01
  • Be sure that all the `DateTime`s in your database are always *stored* in UTC time zone (`UtcNow` instead of just `Now`) and all the communication between the application and the database also uses UTC time zone and wherever you *display* the `DateTime` to the user, use `utcDateTime.ToLocalTime()`. – Corak Apr 25 '13 at 09:16

2 Answers2

4

Instead of DateTime.Now use: DateTime.UtcNow. UtcNow is acording to MSDN:

Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
2

There have also:

obUser.CreationDate = DateTime.UtcNow;

Look on: Converting DateTime.Now To A Different Time Zone

TimeZoneInfo maltaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("...");
DateTime utc = DateTime.UtcNow;
DateTime malta = TimeZoneInfo.ConvertTimeFromUtc(utc, maltaTimeZone )

List of TimeZone List of Timezone ID's for use with FindTimeZoneById() in C#?

static void Main(string[] args)
{
    foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
        Console.WriteLine(z.Id);
}
Community
  • 1
  • 1
Rafal T
  • 339
  • 1
  • 2
  • 14