Question: I'm storing the user's timezone as a decimal in the session. For instance, if the user is in the EST timezone, I'd have 

```
UserTimeZone = -5.00;

```

The data in the database is stored in UTC, so I want to calculate the beginning and the end of the day for that user so that when the user wants his data for a specific day, the records are timezone adjusted.

This is what I'm doing:

```
DateTime StartDate =  DateTime.Now.ToUniversalTime();

StartDate = StartDate.AddHours((double)UserTimeZone);
StartDate = StartDate.Date;
StartDate = StartDate.AddHours((double)UserTimeZone);

DateTime EndDate = StartDate.AddHours(24);

```

The problem I'm having is that this doesn't account for daylight saving time so even thought EST time is 5 hours behind UTC, for the moment it's actually 4 hours behind UTC because of the daylight saving shift.

What are some of your suggestions? Thanks.

Answer: 
The accepted answer doesn't consider that there are time zones that have DST spring-forward transitions right at midnight, and thus the start of the day might not be `00:00` but rather `01:00`. Iran, Cuba, and Brazil (some parts) are good examples.

Additionally, some time zones may have fall-back transitions that give two possible point in time that are midnight.

Consider the following function, which accommodates both scenarios:

```
using System.Linq;

static DateTimeOffset GetStartOfDay(DateTime dt, TimeZoneInfo tz)
{
    // Work in the time zone provided
    if (dt.Kind != DateTimeKind.Unspecified)
    {
        dt = TimeZoneInfo.ConvertTime(dt, tz);
    }

    // Start with assuming midnight
    var d = dt.Date;

    // Check for the time being invalid and handle if so
    if (tz.IsInvalidTime(d))
    {
        // the gap is *usually* 1hr, but not always, so calculate it
        var gap = tz.GetUtcOffset(dt.AddDays(1)) - tz.GetUtcOffset(dt.AddDays(-1));

        // advance forward by the amount of the gap
        d = d.Add(gap);
    }

    // Also check for the time being ambiguous, such as in a fall-back transition.
    // We want the *first* occurrence, which will have a *larger* offset
    var offset = tz.IsAmbiguousTime(d)
        ? tz.GetAmbiguousTimeOffsets(d).OrderByDescending(x => x).First()
        : tz.GetUtcOffset(d);

    // Now we know when the date starts precisely
    return new DateTimeOffset(d, offset);
}

```
You shouldn't be doing any of this. You should just use the TimeZoneInfo built into .net.

For example:

```
TimeZoneInfo.ConvertTimeToUtc();
TimeZoneInfo.ConvertTimeFromUtc();

```

Since you don't seem able to lookup API Parameters, here you go:

<http://msdn.microsoft.com/en-us/library/system.timezoneinfo.converttimefromutc.aspx>

<http://msdn.microsoft.com/en-us/library/bb381744.aspx>