
Making Dates and Times Less Meaningless in Postgres
This is a premium course, which you can purchase below.
Dates and timestamps are core to working with data as you will often find that if you don't know precisely WHEN something happened, it will become meaningless. Dates mark changes over time - those changes will often drive business decisions, so you better be correct!
Bottom line: never trust a spreadsheet. You're going to hear me say that a lot in this production! Especially when it comes to dates.
Postgres is pretty good at dealing with dates... in fact it's amazingly powerful as well as correct:
select now(); -- what date and time is it where my server is located?
select now() + '1 day' as tomorrow; -- adding an interval is extremely easy
select now() at time zone 'America/New_York'; -- specifying a timezone
If you're reading this in a browser, which I assume you are, open up the developer tools using CMD-shift-i (or Ctrl-shift-i on Windows) and open the console.
To see a typical date for JavaScript (and many other languages):
new Date(); //prints out a long-form date
To see an ISO date, which most databases like, you can use:
new Date().toISOString();
This is a format you should let your eyes get used to.