Convert getdate () to int

When I run the following query:

select convert(int, getdate()) 

I get the result:

 ----------- 41238 (1 row(s) affected) 

Does anyone know what this means?

+7
source share
2 answers

The number of days that I think is 1/1/1900 , sql-server stores the number of days since then.

Try dividing this number by approximately 365. You should return the cost over the years (112). Since 1900 + 112 = 2012

+5
source

This is because SQL initially saves the number of days from 01/01/1900

The decimal value after the integer value is the time.

32.5 will be equal to 02/01/1900 12:00 pm

If you want to receive and work with only part of the date as an integer, I would recommend using datepart

This operator will return only a month and convert this value to an integer.

 select convert(int, datepart(mm,getdate()) 
+2
source

All Articles