Menu
Coddy logo textTech

Handling Dates Part 2

Part of the Fundamentals section of Coddy's SQL journey — lesson 32 of 72.

Dates cannot be added or subtracted like numbers. To perform calculations on dates, we must convert them to numbers using the JULIANDAY function.

This function converts dates to the Julian day, a continuous count of days since January 1, 4713 BC, which is used by astronomers for time intervals and comparisons between different calendars.

Note that in the Julian day system, the day begins at noon (12:00:00), so a fractional part of .5 represents exactly noon.

To use it we will write:

SELECT JULIANDAY('2023-02-20 12:00:00')

This will return 2459996.0 days

challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>events</strong>: <strong>id</strong>, <strong>start</strong>, <strong>end</strong>

Fetch the IDs of all events that last less than three days

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals