• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

how to increment a date and time they are split in to fields


I need to do a sweep of a database and increment the start date time by x amount of hours. the hours to increment is derived in an earlier statement. basically i have two fields

START_DATE datetime
START_TIME datetime

I guess i need to cast them into a single field, increment it by the increment value and write it back, I would liked to achieve this in a single statement. Can anyone suggest how this statement might look?

Thanks in advance

0
Michael
Asked:
Michael
1 Solution
 
anandarajpandianCommented:
0
 
pivarCommented:
Hi,

Try:

declare @START_DATE datetime
declare @START_TIME datetime

set @START_DATE='2011-11-01'
set @START_TIME='20:00:00'

select CONVERT(datetime, CONVERT(varchar, DATEADD(hh, 10, @START_DATE+@START_TIME), 101)) as START_DATE,
CONVERT(datetime, CONVERT(varchar, DATEADD(hh, 10, @START_DATE+@START_TIME), 114)) as START_TIME

/peter
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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