Simple Calculation

1. Junior Member
Join Date
Dec 1969
Posts
24

## Simple Calculation

I am new to ASP and SQL but I need help with calculating recordset values. I have two variables, "daysAll" and "daysTak", which both return values from a table through SELECT statements. I just need to know how to subtract "daysTak" from "daysAll" and set it equal to "daysRem". And then can I just use a simple response.write statement to display the calculated value...<BR><BR>Thanks in advance.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Believe it or not...subtract...

You can look at my long explanation of Date/Time values in the ASPFAQs:<BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=189<BR><BR>But the long and short of it is that if you treat a date as a number in VBS (or Access), then it becomes a number-of-days since a start point.<BR><BR>So<BR><BR>daysRem = CDate(Request("daysAll")) - CDate(Request("daysTak"))<BR><BR>The calls to CDATE are because *ALL* Request(xxx) calls always return a string, and you need to convert that string to a Date value.<BR><BR>You should, however, also learn about the DATEDIFF function. Look in the VBScript reference materials (link in left pane of this page) for more on it.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
506

## In SQL...

select (daysTak - daysRem) as &#039;Days&#039; from table

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Are you sure?

In ACCESS, you can do that, yes.<BR><BR>In SQL Server, I&#039;m 80% certain you need to use the DateDiff function?<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sorry...

I was thinking you meant the values are coming from &#060;FORM&#062; input, from a &#060;SELECT&#062;.<BR><BR>If from a DB, you don&#039;t need the CDATE calls.<BR><BR>And, as Camban pointed out, you can do this in the SQL code, if you wish, instead of in VBScript. Doesn&#039;t much matter where you do it, really.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
506

## Maybe:) My impression. Not a date.

Based on the question, I don&#039;t suspect that it&#039;s actually a date, but rather a count of days used and days remaining. In that case basic subtraction will work. If they&#039;re dates, then I&#039;d use the methods you mentioned.

7. Senior Member
Join Date
Dec 1969
Posts
506

## Don't you wish...

that posters would come back after a suggestion is made and fill us in on how it worked, whether it fits their needs or just to say "thanks"? Now I&#039;m wondering if I was confused :)

8. Senior Member
Join Date
Dec 1969
Posts
96,118

...I&#039;d rate it at 60% that you are right and I&#039;m wrong.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
506

## This message has been bookmarked...

Because I simply don&#039;t imaging that that will happen again anytime soon :)

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## The one to bookmark...

...will be the one where he comes back (*if* he ever does, of course) and says you *are* right. 100% is better than 60%.<BR><BR>&#060;grin type=s.e.g./&#062;<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•