September 29, 2010 at 12:25 am
Hi alll,
i am using sql server 2005,
How to add date and time
for exampleeeeee
my date file is 2010-09-29 11:53:00
and add these file 01:00:00
these 2 filed added final i want 2010-09-29 12:53:00
please help mee
regards
pols
September 29, 2010 at 3:53 am
declare @time datetime, @addition int
set @time = '2010-09-29 11:53:00'
set @addition = 1
select dateadd( hh, @addition,@time)
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 29, 2010 at 6:37 am
Yep, pretty much. The dateadd function can manipulate hours, minutes, seconds, days, months, years... whatever you need.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 14, 2011 at 1:30 pm
How would you go about adding actual time fields together?
For instance, you have SQL Agent Job run times as follows:
HH:MM:SS
03:58:19
04:18:42
03:14:09
11:31:10 (which would mean 11 hours, 31 minutes, and 10 seconds)
How you would calculate this?
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 14, 2011 at 1:40 pm
You can just add them together. Example:
select
a.[Date]+a.[Time] as DatePlusTime,
a.*
from
(
select-- Test Data
[Date] = convert(datetime,'2010-09-29 11:53:00') ,
[Time] = convert(datetime,'01:00:00')
) a
Results:
DatePlusTime Date Time
----------------------- ----------------------- -----------------------
2010-09-29 12:53:00.000 2010-09-29 11:53:00.000 1900-01-01 01:00:00.000
January 14, 2011 at 1:59 pm
If I wanted to calculate the average run time for a given SQL Agent job over the past month...knowing that the run_duration column in sysjobshistory is represent as 33848, meaning 3'hours, 38"Minutes, and 48Seconds...
How would I accomplish this?
run_date run_duration
2010121433848
2010121524124
2010121624745
2010121724156
2010121845317
2010122012612
20101221112524
2010122222205
2010122522724
2010122613304
2010122723235
2010122931409
2010123041842
2011010425949
2011010523143
2011010822557
2010122340551
2010122423614
2010122523204
2010122615713
2010122821853
2010123135819
2011010324137
2011010620349
2011010725759
2011010920024
2011011012631
2011011131439
2011011221940
2011011330315
2011011422543
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
January 14, 2011 at 2:08 pm
Serge, you should port your question on a new thread, instead of hijacking an old unrelated thread.
January 14, 2011 at 2:12 pm
Done, thanks for the heads up
http://www.sqlservercentral.com/Forums/Topic1048204-145-1.aspx
______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply