Solved

Concat date part to time part

Posted on 2011-02-28
6
1,008 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parse field in SQL View 15 96
SQL find overlapping events (by time) 2 25
MS SQL Inner Join - Multiple Join Parameters 2 18
SQL Query Syntax Join 4 27
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

919 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

12 Experts available now in Live!

Get 1:1 Help Now