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 464205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:15:06+00:00 2026-05-12T23:15:06+00:00

how to ensure all my datetime is stored as UTC without going through all

  • 0

how to ensure all my datetime is stored as UTC without going through all code? Does this have to be set in db ? how?
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-12T23:15:07+00:00Added an answer on May 12, 2026 at 11:15 pm

    In a web app, there are two ways that a non UTC DateTime can get into your database.

    1) You did it. Search for all occurrences of DateTime.Now. Those need to be DateTime.UtcNow. Still, a find and replace isn’t going to cover it all, because you’ll need to update every place in your code where you display these dates to your users to convert them to local time.

    2) Your user sent you a date/time. There’s no automated way to look for these. You need to manually review every page that the user can use to pass a date/time. Either as data to be saved to your database or as a filter to be used in a query. You’ll need to know their UTC offset and apply it to these occurrences before using them.

    Be sure to capture the user’s UTC offset as soon as they enter your site. As of now, the only way to do this is through javascript. If you have a single entry point (ie a login page) then you can put it there. Otherwise, you’ll need to do it in your master page, or, if you don’t have a master page, every page that they could enter on.

    to get the UTC Offset in javascript use the following code:

    var now = new Date();
    int Offset = now.getTimezoneOffset()
    

    Then pass the offset back to the server. There you can create two functions to handle converting from/to UTC.

    Where UtcOffset holds the javascript Offset:

    public static DateTime ConvertFromUtcToClientTime(DateTime utcDateTime)
    {
        return utcDateTime.AddMinutes(-UtcOffset);
    }
    
    public static DateTime ConvertFromClientTimeToUtc(DateTime clientDateTime)
    {
        return clientDateTime.AddMinutes(UtcOffset);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to ensure all created subprocess are dead at exit time
Relating to my earlier question , I want to ensure all the child objects
How could I ensure that all the clients will always be using the latest
We're using TFS Build Server to ensure that all files checked in by developers
We're all familiar with the horror that is C# event declaration. To ensure thread-safety,
How do you ensure, that you can checkout the code into Eclipse or NetBeans
How do you ensure that the project will be build with good design decisions
I need to ensure that any number of websites and services haven't bitten the
How do you properly ensure that a user isnt tampering with querystring values or
I wish to ensure a user has access to an aspx page by 'Zone'.

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.