Thursday, February 9, 2012

Are there any built in aritmetic capabilities on the Date and Time type?

Simply put, I have a 'Date and Time', (06/03/2006 11:40:00), passed to the SelectCommand via the QueryString. I would like to gain data that is between the supplied time and 1 hour prior.
Is there a simple way to take 1 hr off the 'Date and Time" value or is it necessary to build code that parses the string then adjusts it?

The 'Time' and 'TimeStamp' entities below are both of type 'Date and Time' and all values are gained from the same sql database. I.e. the time used as the basis for selecting the hr period is from the same database as the one where the hour period will be selected from.

Any help would be great.

SelectCommand="SELECT [Timestamp], [Volume] FROM [out8$] WHERE (([CustomerLvl1] = @.CustomerLvl1) AND ([Timestamp] = @.Timestamp))">

<SelectParameters>

<asp:QueryStringParameterDefaultValue="TNT Express"Name="CustomerLvl1"QueryStringField="Cust"

Type="String"/>

<asp:QueryStringParameterDefaultValue="20/02/2006 22:20:00"Name="Timestamp"QueryStringField="Time"

Type="DateTime"/>

Perhaps you could do something like this:

SELECT [Timestamp], [Volume] FROM [out8$] WHERE
[CustomerLvl1] = @.CustomerLvl1) AND [Timestamp] >= @.Timestamp ANDDATEDIFF(hh, [TimeStamp],getdate()) =1

|||For future reference, you can view all the Date and Time functions onMSDN here.

No comments:

Post a Comment