With the release of Angular 12, I decided to rework my Learn With Series of books. A few things really bug me about it, and one of them is how it handles dates.

The books series creates a todo app, and one aspect that always bugged me was the date handling. The date were created local time in the browser, sent to the server, and saved. It often introduced weird issues when loading dates, which I sort of worked around in the code. I remember being very confused on the first rendition of the books because I'd schedule a task for one date and then have it show up on another date. This occurred because the scheduled date stripped out time in the database, causing all sorts of weird issues with conversions from server to UI.

I believe that I should have been saving the dates in UTC from the start, and then formatting them to local day/time when displaying in the UI. I'm working on that as part of the current update.

But, first I need to update the underlying data base so that the dates are stored properly in UTC format.

This query would do that:

view plain print about
2SET dateScheduled = DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()), dateScheduled)

The DateDiff figures out the difference between my time zone and the UTC Time zone. Then it adds those hours onto the database column--dateScheduled. It was a pretty create approach I thought. I stole it from StackOverflow.

The one caveat is that this will only work if all the stored dates are in the same time zone as I am in. For my purposes that was good enough!