Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America

asked on 

Concatenation of Date field or Date only - no timestamp

I am looking to convert a getDate() to display the date only - no time.

here is my currently query.

SELECT     FCStoreCount.StoreCountID, FCStoreCount.DemandSrcID, CURRENT_TIMESTAMP AS PrvMth
FROM         FCStoreCount INNER JOIN
                      FiscalCalendarDaily ON FCStoreCount.FYPeriod = FiscalCalendarDaily.FiscalMonth
WHERE     (DATEPART(m, GETDATE()) + '/' + DATEPART(d, GETDATE()) + '/' + DATEPART(yyyy, GETDATE()) = FiscalCalendarDaily.CalendarDate)

Thanks
Karen
Microsoft SQL Server

Avatar of undefined
Last Comment
aaaaaa
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

If you want to select rows for only a particular date(s), this is the best way to do it:


--assumes CalendarDate column is a DATETIME/SMALLDATETIME type

SELECT     FCStoreCount.StoreCountID, FCStoreCount.DemandSrcID, CURRENT_TIMESTAMP AS PrvMth
FROM         FCStoreCount INNER JOIN
                      FiscalCalendarDaily ON FCStoreCount.FYPeriod = FiscalCalendarDaily.FiscalMonth
WHERE  FiscalCalendarDaily.CalendarDate BETWEEN CONVERT(VARCHAR(8), GETDATE(), 112) AND CONVERT(VARCHAR(8), GETDATE(), 112) + ' 23:59:59.997'  --if DATETIME
-- if SMALLDATETIME, use ' 23:59' instead of ' 23:59:59.997'
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Karen Schaefer
Karen Schaefer
Flag of United States of America image

ASKER

What I am trying to accomplish is to determine the previous months Fiscal Period and retrieve the data based on that date.

I need to retrieve the storecount for 11/1/2004, my calander table has the actual date linked to the fiscal period which is inturned linked to my fcstorecount via the FYPeriod('12/1/2004')

any suggestions.
Karen
Avatar of Karen Schaefer
Karen Schaefer
Flag of United States of America image

ASKER

Getting the next months values if the year changes current mth = 12/1/2004 - next month = 1/1/2005

What is the proper syntax?

SELECT     FiscalCalendarDaily.CalendarDate, FiscalCalendarDaily.FiscalMonth
FROM         FiscalCalendarDaily INNER JOIN
                      FCStoreCount ON FiscalCalendarDaily.FiscalMonth = FCStoreCount.FYPeriod
WHERE     (FiscalCalendarDaily.CalendarDate = iif(Month(CONVERT(datetime, CONVERT(char(12), GETDATE()), 12, DateDiff(y, 1, DATEDIFF(m, 1,
                      CONVERT(datetime, CONVERT(char(12), GETDATE())))), DATEDIFF(m, 1, CONVERT(datetime, CONVERT(char(12), GETDATE()))))

karen
Avatar of aaaaaa
aaaaaa

SELECT     FiscalCalendarDaily.CalendarDate, FiscalCalendarDaily.FiscalMonth
FROM         FiscalCalendarDaily INNER JOIN
                      FCStoreCount ON FiscalCalendarDaily.FiscalMonth = FCStoreCount.FYPeriod
WHERE FiscalCalendarDaily.CalendarDate = CONVERT(char(10), DATEADD(m, 1, GETDATE()), 101)

or

SELECT     FiscalCalendarDaily.CalendarDate, FiscalCalendarDaily.FiscalMonth
FROM         FiscalCalendarDaily INNER JOIN
                      FCStoreCount ON FiscalCalendarDaily.FiscalMonth = FCStoreCount.FYPeriod
WHERE FiscalCalendarDaily.CalendarDate = CONVERT(char(10), DATEADD(m, -1, GETDATE()), 101)
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo