Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Concat date part to time part

Posted on 2011-02-28
6
Medium Priority
?
1,033 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 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 500 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 500 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 500 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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

670 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