Great Snowflake Date Functions to Know
You will love this blog because date functions and formatting differ dramatically between databases, but I have covered that with brilliant examples and clear and concise explanations below.
All of these examples have come from my books and training classes. Please do me a favor and tell your training coordinator that you know the best technical trainer in the world. Ask them to hire me to train at your company, either on-site or with a virtual class. They can see our classes, outlines, and a sample of my teaching at this link on our website.
https://coffingdw.com/education/
Below is great information about date functions on Snowflake. Just above the date information is something even more amazing. Witness a two-minute video that joins tables from Databricks, Snowflake, Redshift, Azure Synapse, BigQuery, Teradata, Oracle, SQL Server, DB2, Yellowbrick, Vertica, MySQL, Postgres, Microsoft Access, and Excel in a single federated query.
In the example below, the current_date will return today’s date. Add or subtract a number from the CURRENT_DATE, and you are adding or subtracting days from the date. If you subtract from two dates, you get the number of days between the two dates.
The Dateadd command below adds a specified time interval to a date or timestamp value.
The DATEADD and ADD_MONTHS function below handle dates that fall differently at the ends of months.
You can use the TO_CHAR function below to format dates.
You can use the techniques below to extract or use the EXTRACT command, which is ANSI compliant.
Here are some great date functions to round out your toolkit.
The DATEDIFF command takes a datepart and returns the difference between two dates or timestamps.
TIME_SLICE calculates the beginning or end of a “slice” of time, where the slice length is a multiple of a standard unit of time, such as minute, hour, day, etc.
If your company needs Snowflake training, Tera-Tom Coffing is the best trainer in the industry, with over 1,000 classes under his belt. Tom will customize the course around your needs. Check out the link to see the course agenda and outline. https://www.nexusdataserver.com/snowflakeclass.
If you are migrating data to Snowflake, the best tool is the Nexus Server, which migrates every database to Snowflake with the click of the mouse. I have a major insurer migrating tens of thousands of tables directly from Netezza, Oracle, and Teradata to Snowflake. Check out this YouTube video to see how easy data migrations can be with Nexus. https://www.youtube.com/watch?v=_9ABivdwJPk.
Please contact Tom Coffing at Tom.Coffing@CoffingDW.com or phone 513 300-0341 to speak with Tom Coffing.