Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1061103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:25:41+00:00 2026-05-16T18:25:41+00:00

I am writing a fairly large webapp in asp.net/c# with MSSQL 2008 r2 serving

  • 0

I am writing a fairly large webapp in asp.net/c# with MSSQL 2008 r2 serving the database. The program needs to convert date/time strings (in ISO date format) to DateTime where they are used and later stored as smalldatetime in sql.

When the strings are converted to datetimes, an hour is mysteriously added to the result. I understand that being in the UK, we are subjected to daylight savings time (currently active) but surely the datetime.convert method understands this? When converting back to a string, the result is as expected.

I have written a small program to illustrate the problem (also including non ISO dates for my sanity):

class Program
{


    static void Main(string[] args)
    {
        //BB();
        //Dist();
        DateTime d1 = new DateTime();
        DateTime d2 = new DateTime();
        string d1s = "2010-09-13T09:30:01Z";
        string d2s = "2010-09-13 09:30:01";

        d1 = Convert.ToDateTime(d1s);
        d2 = Convert.ToDateTime(d2s);

        Console.WriteLine("d1s:{0} d1:{1} ", d1s, d1);
        Console.WriteLine("d2s:{0} d2:{1} ", d2s, d2);

        d1s = d1.ToString("u"); d2s = d2.ToString("u");

        Console.WriteLine("\nd1: {0}", d1s);
        Console.WriteLine("d2: {0}", d2s);

        d1 = Convert.ToDateTime(d1s);
        d2 = Convert.ToDateTime(d2s);

        Console.WriteLine("\nd1s:{0} d1:{1} ", d1s, d1);
        Console.WriteLine("d2s:{0} d2:{1} ", d2s, d2);

        Console.Read();
    }
}

Here are the results I get when I run the program:

d1s:2010-09-13T09:30:01Z d1:13/09/2010 10:30:01
d2s:2010-09-13 09:30:01 d2:13/09/2010 09:30:01

d1: 2010-09-13 10:30:01Z
d2: 2010-09-13 09:30:01Z

d1s:2010-09-13 10:30:01Z d1:13/09/2010 11:30:01
d2s:2010-09-13 09:30:01Z d2:13/09/2010 10:30:01
Done

Is this the correct behavior? Am I being an idiot? I would have expected converting datetime to string and then the exact string back to datetime would give back the original input. If this is the correct behavior, any ideas on how to get a consistant result but still using Convert.ToDateTime()?

Many Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:25:42+00:00Added an answer on May 16, 2026 at 6:25 pm

    The ‘Z’ at the end of the datetime means “Zulu” (equivalent of UTC/GMT). By default when you convert a string with that at the end of it it will convert it to local time (+ 1 hour in your case).

    Without the ‘Z’ .NET will assume the date is already in the correct format and not add the hour.

    When you format the datetime back into a string you are using the format string of “U”. This is telling .NET that it is a UTC time and should be formatted at such. Therefore it adds the ‘Z’ to the end. When you convert it back to a date time another hour is added to make it local.

    To clarify:

    d1: Starts as a UTC string -> local time (+ 1 hour) -> UTC string -> local time (+1 hour)

    d2: Starts as a local string -> local time (no change) -> UTC string -> local time (+ 1 hour)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a fairly large and complex data analysis program and I have
I am writing a fairly large C++ shared-object library, and have run into a
I'm writing a solution around MOSS 2007. And storing fairly large quantities of data
I'm fairly new to Java and am writing an app that needs an XML
I have a Python program that processes fairly large NumPy arrays (in the hundreds
I'm using NHibernate and Microsoft Access. My database file is fairly large ( ~500
The app I'm writing needs to get information from a remote database and then
I'm writing a wrapper around a fairly large unmanaged API. Almost every imported method
I'm writing a (fairly) simple C# application using .NET 4 to check for updates
I'm writing a fairly large query, and I have 2 tables, inner joined and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.