Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
SQL Server uses '1900-01-01' as a "zero-point" in DATEDIFF(dd, 0, some_date): select DATEDIFF(dd, 0, '1900-01-01') --> 0 select DATEDIFF(dd, 0, GETDATE()) --> 44066 days since the "zero-d...
Answer
#3: Post edited
- SQL Server uses '1900-01-01' as a "zero-point" in `DATEDIFF(dd, 0, some_date)`:
- select DATEDIFF(dd, 0, '1900-01-01') --> 0
- select DATEDIFF(dd, 0, GETDATE()) --> 44066 days since the "zero-day"
- The whole expression is used to strip time from the `DATETIME` and still have it as a DATETIME (as opposed to DATE). An alternative would be to `CAST` it to DATE, but it will change the type:
- select CAST(GETDATE() AS DATE) --> 2020-08-25 (no time)
- What is more interesting is that the minimum DATETIME is not '1900-01-01', but 1753-01-01 which of course corresponds to a negative integer value:
- select cast(-53690 as datetime)
- Relevant resources:
[SQL Server function to return minimum date ](https://stackoverflow.com/questions/3825893/sql-server-function-to-return-minimum-date-january-1-1753)[Best approach to remove time part of datetime in SQL Server](https://stackoverflow.com/questions/1177449/best-approach-to-remove-time-part-of-datetime-in-sql-server)
- SQL Server uses '1900-01-01' as a "zero-point" in `DATEDIFF(dd, 0, some_date)`:
- select DATEDIFF(dd, 0, '1900-01-01') --> 0
- select DATEDIFF(dd, 0, GETDATE()) --> 44066 days since the "zero-day"
- The whole expression is used to strip time from the `DATETIME` and still have it as a DATETIME (as opposed to DATE). An alternative would be to `CAST` it to DATE, but it will change the type:
- select CAST(GETDATE() AS DATE) --> 2020-08-25 (no time)
- What is more interesting is that the minimum DATETIME is not '1900-01-01', but 1753-01-01 which of course corresponds to a negative integer value:
- select cast(-53690 as datetime)
- Relevant resources:
- [SQL Server function to return minimum date ](https://stackoverflow.com/questions/3825893/sql-server-function-to-return-minimum-date-january-1-1753) from Stack Overflow.
- [Best approach to remove time part of datetime in SQL Server](https://stackoverflow.com/questions/1177449/best-approach-to-remove-time-part-of-datetime-in-sql-server) from Stack Overflow.
#2: Post edited
- SQL Server uses '1900-01-01' as a "zero-point" in `DATEDIFF(dd, 0, some_date)`:
- select DATEDIFF(dd, 0, '1900-01-01') --> 0
select DATEDIFF(dd, 0, GETDATE()) --> 44066- The whole expression is used to strip time from the `DATETIME` and still have it as a DATETIME (as opposed to DATE). An alternative would be to `CAST` it to DATE, but it will change the type:
- select CAST(GETDATE() AS DATE) --> 2020-08-25 (no time)
- What is more interesting is that the minimum DATETIME is not '1900-01-01', but 1753-01-01 which of course corresponds to a negative integer value:
- select cast(-53690 as datetime)
- Relevant resources:
- [SQL Server function to return minimum date ](https://stackoverflow.com/questions/3825893/sql-server-function-to-return-minimum-date-january-1-1753)
- [Best approach to remove time part of datetime in SQL Server](https://stackoverflow.com/questions/1177449/best-approach-to-remove-time-part-of-datetime-in-sql-server)
- SQL Server uses '1900-01-01' as a "zero-point" in `DATEDIFF(dd, 0, some_date)`:
- select DATEDIFF(dd, 0, '1900-01-01') --> 0
- select DATEDIFF(dd, 0, GETDATE()) --> 44066 days since the "zero-day"
- The whole expression is used to strip time from the `DATETIME` and still have it as a DATETIME (as opposed to DATE). An alternative would be to `CAST` it to DATE, but it will change the type:
- select CAST(GETDATE() AS DATE) --> 2020-08-25 (no time)
- What is more interesting is that the minimum DATETIME is not '1900-01-01', but 1753-01-01 which of course corresponds to a negative integer value:
- select cast(-53690 as datetime)
- Relevant resources:
- [SQL Server function to return minimum date ](https://stackoverflow.com/questions/3825893/sql-server-function-to-return-minimum-date-january-1-1753)
- [Best approach to remove time part of datetime in SQL Server](https://stackoverflow.com/questions/1177449/best-approach-to-remove-time-part-of-datetime-in-sql-server)
#1: Initial revision
SQL Server uses '1900-01-01' as a "zero-point" in `DATEDIFF(dd, 0, some_date)`: select DATEDIFF(dd, 0, '1900-01-01') --> 0 select DATEDIFF(dd, 0, GETDATE()) --> 44066 The whole expression is used to strip time from the `DATETIME` and still have it as a DATETIME (as opposed to DATE). An alternative would be to `CAST` it to DATE, but it will change the type: select CAST(GETDATE() AS DATE) --> 2020-08-25 (no time) What is more interesting is that the minimum DATETIME is not '1900-01-01', but 1753-01-01 which of course corresponds to a negative integer value: select cast(-53690 as datetime) Relevant resources: [SQL Server function to return minimum date ](https://stackoverflow.com/questions/3825893/sql-server-function-to-return-minimum-date-january-1-1753) [Best approach to remove time part of datetime in SQL Server](https://stackoverflow.com/questions/1177449/best-approach-to-remove-time-part-of-datetime-in-sql-server)