Skip to content

Instantly share code, notes, and snippets.

@robconery
Created September 28, 2023 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robconery/2f9ebb55011799cf00d62393c65e3407 to your computer and use it in GitHub Desktop.
Save robconery/2f9ebb55011799cf00d62393c65e3407 to your computer and use it in GitHub Desktop.
SQL Tangent Dates

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment