If you want to go directly to the solution: Click [here](Go-to-solution)
One of my biggest mistakes in the past was the Datetime value in SQL. Seriously.
In all my code when i want to create a registry in the database, one of my practices is using the created_at, because who knows! Maybe in the future will be neccessary.
But, in my curiosity checked in which hour are more often the registrations and it was very strange to see hours like “1 AM” or “3:30 PM” because well, or everybody are sleeping or working.
So, let’s go to basic!
Facing the problem
It is time to do the research 🔍.
- The first suspect – SQL
I use Azure SQL databases because it’s more familiar for me -and i’m to lazy to use another one- but it is really cool to use Entity Framework with Microsoft SQL out-of-the-box, maybe this is the main reason.
Yeah i know, there are many ways to check the server hour in sql, but i like this one, it’s very simple.
The result? It’s different, then, maybe this is the culprit, but one of my teachers in the past told me:
“If it’s too easy is because or it was or you are doing it wrong.”
I need one more suspect before finish my research.
- The second suspect – Entity Framework
My favorite ORM, maybe it’s not the best but it is always there, like a buddy.
In local, i run SQL Server Profiler to check the final query for insert into the database… and notice something strange.
The final code includes the datetime already in the insert query. Aha! I know it was not that easy. I need to go even further back.
- The final suspect – Server
How can i check the date in the server if i was using an App Service? It was my first thought.
Checking out the options in the azure app’s panel, i look that there is a console option(under Development Tools), when i clicked on it, it was an Powershell!
I’m not expert, but there is 2 useful commands to check it out what is going on, date and time, and the second one was the answer of all of this.
The solution 🧙♂️
Finally, it’s time to fix this.
Under settings, click on Application Settings.
There are 4 different configuration things, you need to go to Application Configuration section and add a new setting “WEBSITE_TIME_ZONE”.
In value, you need to find your timezone and add the value, for me, it was Central Standard Time.
Click on save, wait for the finish and you are done!
Today we learn:
- How-to know the date and the time using SQL Server
- Azure App Services have a hidden console
- How-to change the timezone of an azure app service
Are you in trouble? Have any questions? Contact me
I am a mexican Back-End Developer with 6 years of experience and 3 year of MSSQL Database Administrator. Experienced with all stages of the development cycle for web apps. Strong experience in project management and leadership.