Date and Time Functions

Renée M. P. Teate · 2021

Data scientists use date and time functions many different ways in queries. This chapter looks at some different ways to work with date and time values in Farmer's Market database. Depending on the database system used, the function that retrieves different portions of a datetime value may be called EXTRACT (MySQL), DATE_ PART (Redshift), or DATEPART (Oracle and SQL Server). The example Farmer's Market database is in MySQL, so these examples use EXTRACT(), but the concepts are the same for the other functions, even though the syntax will vary. The chapter uses the market_start_datetime and market_end_ datetime fields to demonstrate. DATEDIFF is a SQL function available in most database systems that accepts two dates or datetime values, and returns the difference between them in days. The DATEDIFF function returns the difference in days, but there is a function in MySQL called TIMESTAMPDIFF that returns the difference between two datetimes in any chosen interval.

Read the paper · More papers on PaperTik