Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Get system date

Now do I get the system date as a number in MS Query?
0
cd_morris
Asked:
cd_morris
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now