Hi
I want to get data whose time is 72 Hrs later from current Date. I have data like below.
FromDate FromTime
2022-09-11 09:00:00.0000000
2022-09-06 13:00:00.0000000
2022-10-08 08:45:00.0000000
2022-10-20 08:00:00.0000000
Thanks
Hi
I want to get data whose time is 72 Hrs later from current Date. I have data like below.
FromDate FromTime
2022-09-11 09:00:00.0000000
2022-09-06 13:00:00.0000000
2022-10-08 08:45:00.0000000
2022-10-20 08:00:00.0000000
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 3, 2023, 5:48 AM EST
Hi Ramco,
To get the data whose time is 72 hours (3 days) later from the current date, you can use the following SQL query:
SELECT * FROM your_table_name WHERE DATEADD(HOUR, 72, CONVERT(datetime, CONCAT(FromDate, ' ', FromTime))) >= GETDATE()This query adds 72 hours to the FromDate and FromTime columns to get a future date and time, and then compares it to the current date using the GETDATE() function. The DATEADD function is used to add hours to the combined FromDate and FromTime columns, and the CONCAT function is used to combine the two columns into a single datetime value. Make sure to replace your_table_name with the actual name of your table.
Hope this helps.
Nitin SontakkeRank #264 · 9.6K reputationPosted Oct 5, 2022, 10:52 PM EDT
Hello,
You want database side solution (which database?) or programming language (which language?) solution.
Is this infornation stored in two separate columns / variables? If yes, you will have to first combine them together to form a datetime variable for sure.
On Microsoft SQL Server side you have dateadd function which takes several arguments, hours being one of them.
On Microsoft .NET side, the datetime structure has .AddHours method which returns new datetime structure.
Hope it helps!
Rajeev KumarRank #1,334 · 1.3K reputationPosted Mar 3, 2023, 4:57 AM EST
string sDateTime = "12/12/2007 11: 07:25 AM"; // retrive the values of year, month and day string yyyy, mm, dd; yyyy = sDateTime.Substring(0, 2); // please work out with the start index mm = sDateTime.Substring(2, 2); dd = sDateTime.Substring(5, 2); DateTime dt1 = new DateTime(yyyy, mm, dd); DateTime dt2 = new DateTime(yyyy, mm, dd + 3); // add or sub 3 days if (dt2 < dt1) { // enable or disable the button }