What is DB independent (works for both mysql and sqlite3) for calculating the days between two dates in SQL?

Datediff is a function used in mysql and sql server to calculate days between two dates. However, Datediff does not work in sqlite3. What is DB independent (works for mysql and sqlite3) way of calculating days between two dates? Many thanks.

+3
source share
1 answer

If you correctly manage your data types, you can do the work of subtraction correctly and in exactly the same way in all three systems.

Since SQLite does not have a datetime data type, you can store date values ​​as integers and usually subtract dates.

MSSQL allows you to subtract datetime, and when used as an int will give you the number of days between them.

MySQL must allow the subtraction of DATE data types. (You can check it out.)

0
source

All Articles