I have two problems.
How can I get today's date without time?
How can I convert
datetime
type intoint
type?
I have two problems.
How can I get today's date without time?
How can I convert datetime
type into int
type?
Just use the following queries:
Q1:How can I get Today's date without time ?
SELECT CONVERT(DATE, GETDATE());
Q2:How can I convert datetime type into int type ?
SELECT YEAR(GETDATE()) * 10000 + MONTH(GETDATE()) * 100 + DAY(GETDATE())
Dates are stored as a decimal value, you did not specify how you want to construct your int.
Do you want the actual decimal value ?
you can see the value like this
select CONVERT(float, getdate())
if you only need the date, then this can help
select convert(int, convert(datetime, convert(date, getdate())))
or
select convert(int, getdate(), 112)
Both methods will return an int value for the given date.
For 22/06/2021
this will return 44367
or if you just want to convert the formatted value, then the easiest way is this
select convert(int, Convert(CHAR(8), getdate(), 112))
For 22/06/2021
this will return 20210622