Get system date

Now do I get the system date as a number in MS Query?
LVL 4
cd_morrisAsked:
Who is Participating?
 
Aneesh RetnakaranDatabase AdministratorCommented:
Select getdate()
0
 
ralmadaCommented:
try like this
select format(date(), 'general number')
0
 
k_murli_krishnaCommented:
select getDate() gives 2009-11-17 21:56:40.357. You want system date as a number.

CREATE FUNCTION [dbo].[ufn_GetDateOnly] ( @pInputDate    DATETIME )
RETURNS INTEGER
BEGIN

    RETURN CAST(CAST(YEAR(@pInputDate) AS VARCHAR(4)) +                 CAST(MONTH(@pInputDate) AS VARCHAR(2)) +
                CAST(DAY(@pInputDate) AS VARCHAR(2)) AS INT)

END
GO

Instead of function above, this query should work:

SELECT CAST(CAST(YEAR(getDate()) AS VARCHAR(4)) +                 CAST(MONTH(getDate()) AS VARCHAR(2)) +
                CAST(DAY(getDate()) AS VARCHAR(2)) AS INT)

You can change the order of YEAR, MONTH and DAY.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
sameer2010Commented:
Use this:
select datepart(yy,getdate()) * 10000 + datepart(mm,getdate())*100
+datepart(dd,getdate()) as NumberDate;

Open in new window

0
 
ralmadaCommented:
Guys, did anybody notice that the asker mention MS Query, not MS SQL Server? That's why I've suggested comment http:#a26073039.
cd_morris, can you please clarify if I'm wrong?
Thanks.
0
 
ralmadaCommented:
OK, your question was "Now do I get the system date as a number in MS Query?"
MS Query is part of the Excel application. Is not MS SQL Server. Can you please advise why you selected that answer?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.