locked
Time restriction from different country zones RRS feed

  • Question

  • User-284642143 posted

    I am attempting to calculate the difference between two times. One is stored on the database and the other is the current date and time when the user visits

    DateTime start = valueFromDb; 
    DateTime finish = DateTime.Now;
    TimeSpan span = finish.Subtract(start);
    
    // if over 20 minutes redirect to an expiry page.

    I use this to workout if there is more than 20 minutes from the value from the database.

    What my concern is if this site is visited from another country (lets say 5 hours behind my local time), would it mean they would have an additional 5 hours or would the finish time (if they visited on the same day) be from the server in my country? I wasnt sure how i could test this. Some suggest using UTC but i now have existing data stored in the database.

    Example

    Database time: 06-12-2019 09:00
    My local time: 06-12-2019 10:00

    So the expiry time is 09:20. Lets say someone from another country visits where their local time is 06-12-2019 02:00, what would happen in that case?

    Friday, December 6, 2019 12:36 PM

Answers

  • User475983607 posted

    What my concern is if this site is visited from another country (lets say 5 hours behind my local time), would it mean they would have an additional 5 hours or would the finish time (if they visited on the same day) be from the server in my country?

    DateTime.Now runs on the web server not the client machine.  This is only a problem if the web server is in a different timezone than the DB.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 12:43 PM
  • User475983607 posted

    Both the site and database are based in the same country. So regardless of their local time 20 minutes expiry is 20 minutes regardless of the country they visit from?

    DateTime.Now reads the system clock on the web server.  You did not post any code that accepts user data time inputs.

    A quick sub question: Is there a particular instance to use UTC i.e. DateTime.ToUtcDateTime?

    DateTime.ToUtcDateTime reads the system clock which has the time zone and converts the DateTime to UTC.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 1:11 PM

All replies

  • User475983607 posted

    What my concern is if this site is visited from another country (lets say 5 hours behind my local time), would it mean they would have an additional 5 hours or would the finish time (if they visited on the same day) be from the server in my country?

    DateTime.Now runs on the web server not the client machine.  This is only a problem if the web server is in a different timezone than the DB.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 12:43 PM
  • User-284642143 posted

    Both the site and database are based in the same country. So regardless of their local time 20 minutes expiry is 20 minutes regardless of the country they visit from?

    A quick sub question: Is there a particular instance to use UTC i.e. DateTime.ToUtcDateTime?

    Friday, December 6, 2019 12:47 PM
  • User475983607 posted

    Both the site and database are based in the same country. So regardless of their local time 20 minutes expiry is 20 minutes regardless of the country they visit from?

    DateTime.Now reads the system clock on the web server.  You did not post any code that accepts user data time inputs.

    A quick sub question: Is there a particular instance to use UTC i.e. DateTime.ToUtcDateTime?

    DateTime.ToUtcDateTime reads the system clock which has the time zone and converts the DateTime to UTC.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 6, 2019 1:11 PM
  • User-284642143 posted

    EssCee

    Both the site and database are based in the same country. So regardless of their local time 20 minutes expiry is 20 minutes regardless of the country they visit from?

    DateTime.Now reads the system clock on the web server.  You did not post any code that accepts user data time inputs.

    The DateTime stored on the database is inserted automatically when a user saves a record. The user does not have the option to insert the date manually. I use DateTime.Now to store the value to the table.

    Friday, December 6, 2019 3:33 PM