943,614 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 13072
  • ASP.NET RSS
Feb 29th, 2008
0

How to calculate and compare DateTime with Integer(c#)

Expand Post »
Example:

I have a table name A and have three column name OVER_DUE_DATE_TIME(date/time), DUE_DATE_TIME(date/time) and DURATION(Integer, in hours).

I need to do this validation: DUE_DATE_TIME + DURATION <= OVER_DUE_DATE_TIME

If the validation is wrong then should prompt the user error message.

May I have this solution in C# !!


Thanks in advance !!
hwa
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hwa is offline Offline
17 posts
since Feb 2008
Feb 29th, 2008
0

Re: How to calculate and compare DateTime with Integer(c#)

you can do this with retrieving the information from the SQL server:

DATEADD(dd, DURATION, DUE_DATE_TIME)

Taking into account that DURATION is the integer in the amount of days (7 for a week, 14 for two weeks, etc.)

Otherwise make sure that your DUE_DATE_TIME is a valid date, then set it to a variable and add the duration to it:

date DDT = DUE_DATE_TIME;
DDT = DDT.AddDays(parseInt(DURATION));

if (DDT > OVER_DUE_DATE_TIME)
{
response.write("book is overdue");
}

Again, taking into account that duration is an integer in the amount of days.
Last edited by SheSaidImaPregy; Feb 29th, 2008 at 12:23 pm.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Mar 1st, 2008
0

Re: How to calculate and compare DateTime with Integer(c#)

you can do this with retrieving the information from the SQL server:

DATEADD(dd, DURATION, DUE_DATE_TIME)

Taking into account that DURATION is the integer in the amount of days (7 for a week, 14 for two weeks, etc.)

Otherwise make sure that your DUE_DATE_TIME is a valid date, then set it to a variable and add the duration to it:

date DDT = DUE_DATE_TIME;
DDT = DDT.AddDays(parseInt(DURATION));

if (DDT > OVER_DUE_DATE_TIME)
{
response.write("book is overdue");
}

Again, taking into account that duration is an integer in the amount of days.

I want the Duration in Hours.

If the DUE_DATE_TIME(the time) + the DURATION is next day then the DUE_DATE_TIME should be increase one day and then compare to the OVER_DUE_DATE_TIME.
hwa
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hwa is offline Offline
17 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: login validation
Next Thread in ASP.NET Forum Timeline: drop down list selected index change doesn't work in mozilla





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC