473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Add 2 hours to a time value!

jullianps
Hi Guys and lets start by saying that this is my first post, I would like to thank in advance to those who can give me a hand and lets start with the quesiton...

The problem probably could sound super easy for some of you but I cant figure out how to do it yet, I have a Datetime field on a MS SQL server DB and it gets its default value through Getdate() and it works fine but the problem is that I need to add 2 hours to the ending time (which is part of the value since it contains the date too) for example:


2/27/2008 8:21:13 AM <--------------This is in my DB now

2/27/2008 10:21:13 AM <--------------This is what I would like to have

Probably it can be done at the very moment of insertion or probably it needs to be done after the value has been inserted through an update in some sort.


Again thanks for the help provided
Marco
Feb 27 '08 #1
3 12001
ck9663
2,878 Expert 2GB
You're looking for DATEADD function. Just use hour as your datepart.

-- CK
Feb 27 '08 #2
Thanks so much Ive opened the link and it looks like what I need !
Marco
Feb 27 '08 #3
Awesome, Worked like a charm I ended up adding a trigger for Insert and this was the simple Update statement that made it work


CREATE TRIGGER [Add2hours] ON [DB].[dbo].[Table]
FOR INSERT
AS
Update fileslog set date_time=DATEADD(hh, 2, date_time)


Thanks for the tip
Marco
Feb 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
3
by: John McGinty | last post by:
Hello Chaps, Just a little sounding on removing out of hours from some datetime date that I have. Basically we have a helpdesk that logs calls when they are entered and when they are resolved....
3
by: Reney | last post by:
I am using Access Database in my program. The column in the table that I am going to use has date/time value with Medium Time selected. (HH:mm). The program is recording a clock in time to this...
2
by: Niclas | last post by:
Hi, I need to insert a time value from my ASP .Net web application in the format Minute:Second:Millisecond to a SQL column typed with datetime. The approach i was thinking of was to...
6
by: Rich | last post by:
Hello, I have a label in my app where I display time from a Timer contol like this: Private Sub Timer1_Tick(...) Handles Timer1.Tick lbl_Time.Text = TimeOfDay.ToString End Sub The display...
6
by: Aussie Rules | last post by:
Hi, I have a datepicker that show a calender. The user picks a date and the time component is always 00:00. I then have a drop down that provides a list of times, (10:00, 11:00 etc), and I...
2
by: John Dann | last post by:
I have a standard .Net DateTime variable to which I want to add a time value. The catch is that the time value is only readily available as a string as "HH:mm". Question is whether there's a...
23
by: tatata9999 | last post by:
Hi, What time zones tend to use 24 hours time format? Googling hasn't been able to answer the question. Thank you.
1
by: pvenkatesh2k4 | last post by:
hi i need to store the time value alone in sql server database.i declared datetime type for that particular field. while inserting i need to store only time value, but it stores date also. how to...
4
by: crs27 | last post by:
Hai All, This is my create statement CREATE TABLE `dbname`.`tablename` ( `vh_id` int(10) unsigned NOT NULL, `gh_utc` time NOT NULL, `gh_mydate` date default NULL, `gh_serverdate_time`...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.