In PostgreSQL, we can use the +
operator to add one or more weeks to a date. We have a few options when it comes to specifying the actual number of weeks.
Tag: dates
2 Ways to Return the Unix Timestamp in SQLite
The unix timestamp is the number of seconds since 1970-01-01 00:00:00 UTC. SQLite provides us with a couple of ways to get the unix timestamp.
Continue readingGet the First Monday of a Month in SQLite
SQLite’s DATE()
function provides us with the ability to return the date of the first instance of a given day of a given month. Therefore, we can use it to return the first Monday of a given month. We can also use it to return the first Tuesday, Wednesday, Thursday, Friday, etc.
We can use DATETIME()
if we want a datetime value to be returned.
Get the Date/Time from a Unix Timestamp in SQLite
If you have a Unix timestamp, you can use SQLite’s DATETIME()
function with the unixepoch
modifier to compute the actual date and time.
You can alternatively use the DATE()
function if you only need the date to be returned. And it’s also possible to use the TIME()
function to return just the time portion.
Add Months to a Date in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more months to a date. There are several options when it comes to specifying the actual number of months.
Return the End of the Month in SQLite
In SQLite, we can use the following method to calculate the last day of a given month.
We can base this either on the current date, or on some other specific date.
Continue readingReturn the Start of the Month in SQLite
SQLite gives us the ability to return the date of the beginning of the month, based on a given date.
This means we can return the date of the first day of the current month, or the first day of the month based on a date that we specify.
This allows us to perform further calculations on the resulting date, like adding a given number of days to it.
Continue readingSubtract Years from a Date in SQLite
In SQLite, we can use the DATE()
function to subtract one or more years from a date.
For datetime values, we can use the DATETIME()
function.
Add Days to a Date in PostgreSQL
The +
operator allows us to add one or more days to a given date in PostgreSQL. We have a few options when it comes to specifying the actual number of days.
SQLite DATEADD() Equivalent
SQLite doesn’t have a DATEADD()
function like SQL Server (or an ADDDATE()
or ADD_DATE()
function like in some other DBMSs), but it does have the DATE()
function that can make additions to a date value.
SQLite also has a DATETIME()
function that can make additions to a datetime value (as well as a TIME()
function for time values).