Solved

Concat date part to time part

Posted on 2011-02-28
6
1,005 Views
Last Modified: 2012-05-11
This is SQL 2000....

I have a piece of SQL code and I do a comparision. See below.
That works but I created a table to hold "cut off" hours for shipments. Now, I dont know how to do the comparison..i somehow need to concat "date" of "getdate" to "time" from the table...then do the comparison..

see below please
--This is how it currently works...we want to check the *hour*
DECLARE @CUTOFF DATETIME
declare @poDate datetime

SET @CUTOFF = dateadd(hour,16,CONVERT(VARCHAR,GETDATE(),101))
set @poDate ='2011-02-04 10:38:00.000'

-- Then compare
If @poDate <= @cutoff Begin
 .....
End

------ This is what i want to do -----------

-- But for cutoff date, I created a table with values like this, looking at the *hour*
 --1900-01-01 15:00:00.000
 --1900-01-01 19:00:00.000
create table #cutoff
(
   id int identity,
   shipmethod varchar(20),
   cutoffHour datetime

)
insert into #cutoff ('USPS','1900-01-01 16:00:00.000')
insert into #cutoff ('UPSA','1900-01-01 19:00:00.000')
/*
But now, the date is "1900-01-01" and I cant just do a comparision. I think I need to somehow get the "date" part from getdate()
and concat it to Time part and then do the comparision. 
*/
select @cutoffhour = cutoffhour from #cutoff --somehow concat Date of getdate to time from cutoff hour

If @poDate <= @cutoffHour Begin
 .....
End

Open in new window

0
Comment
Question by:Camillia
6 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 125 total points
ID: 35002974
create table #cutoff
(
   id int identity,
   shipmethod varchar(20),
   cutoffHour datetime

)
insert into #cutoff  select 'USPS',CONVERT(varchar(10) , GETDATE(), 120)+' 16:00:00.000'
insert into #cutoff  select 'UPSA',CONVERT(varchar(10) , GETDATE(), 120)+' 19:00:00.000'

select * from #cutoff
0
 
LVL 6

Expert Comment

by:Rajesh_mj
ID: 35003937
pls check below code. It will  concat "date" of "getdate" to "time" from the table:

select cast(getdate() as int)+ @cutoffhour
0
 
LVL 6

Assisted Solution

by:anushahanna
anushahanna earned 125 total points
ID: 35003945
the below are other date formats you can put to use:
http://www.sql-server-helper.com/tips/date-formats.aspx
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 125 total points
ID: 35004470
IF YOU HAVE A CUT OFF HOUR THEN WHY NOT JUST STORE The hour and compare the hours?


isn't your table too simplistic? won't the cut off time depend on the actual date/day of week etc....

so you should have two tables... 1 for the default  cut off hours per day of the week... by method
and the second as an exception table to cater for national holidays etc....

hour(date)

convert(char(8),getdate(),112)  give the YYYYMMDD date to which you can then attach a character time component

 as HH:MM  (with a space between the date and the time component....
0
 
LVL 9

Assisted Solution

by:rajeevnandanmishra
rajeevnandanmishra earned 125 total points
ID: 35007117
Hi,

In your original query you can use the below line:
 
select @cutoffhour = convert(char(10), @poDate, 111) 
              + cutoffhour from #cutoff --somehow concat Date of getdate to time from cutoff hour

Open in new window


And this will include your cutOffHour with the PoDate.
0
 
LVL 7

Author Comment

by:Camillia
ID: 35007430
going to try now. will post back
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now