Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP DATE between NOW and 24 HOURS earlier.

Reply
Thread Tools

ASP DATE between NOW and 24 HOURS earlier.

 
 
Darren
Guest
Posts: n/a
 
      01-26-2004
Hello,

How would I write in SQL or ASP the following?:
Count number of Database Records between NOW and 24 HOURS EARLIER? I know
how to retrieve recordsets etc - its just the date thing I cant grasp. I am
stuck getting the 24 hours earlier data capture.

Thanks!

Gary.
PS - Sorry for the X-Posting. Just need to answer fairly quickly if at all
possible. Hopefully relevant to all groups!


 
Reply With Quote
 
 
 
 
Jon Davis
Guest
Posts: n/a
 
      01-26-2004
Try this C#:

string yesterday = DateTime.Now.AddDays(-1).ToString();
string now = DateTime.Now.ToString();
string sSQL = "SELECT * FROM FIELD "
+ "WHERE DATE > '" + yesterday + "' AND DATE <= '" + now + "'";

Untested; might be a minor syntax typo but your compiler should catch it.
For instance, I don't remember if dates are 'date' or %date%.


"Darren" <(E-Mail Removed)> wrote in message
news:bd_Qb.9794$(E-Mail Removed)...
> Hello,
>
> How would I write in SQL or ASP the following?:
> Count number of Database Records between NOW and 24 HOURS EARLIER? I know
> how to retrieve recordsets etc - its just the date thing I cant grasp. I

am
> stuck getting the 24 hours earlier data capture.
>
> Thanks!
>
> Gary.
> PS - Sorry for the X-Posting. Just need to answer fairly quickly if at

all
> possible. Hopefully relevant to all groups!
>
>



 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      01-26-2004
Darren wrote:
> Hello,
>
> How would I write in SQL or ASP the following?:
> Count number of Database Records between NOW and 24 HOURS EARLIER? I
> know how to retrieve recordsets etc - its just the date thing I cant
> grasp. I am stuck getting the 24 hours earlier data capture.
>
> Thanks!
>
> Gary.
> PS - Sorry for the X-Posting. Just need to answer fairly quickly if
> at all possible. Hopefully relevant to all groups!


Look, this is a asp and database question. Unless you are using .Net, there
is ONE relevant group for this question: .inetserver.asp.db. Cross-posting
to thousands of semi-related groups will NOT get you a quicker answer.

I would set follow-ups to .inetserver.asp.db if your inclusion of the
dotnet groups hadn't raised the doubt that you might be using .Net.

Why don't you post back to the relevant newsgroup and let us know what
technology you are using (asp or asp.net) AND what type and version of
database you are using (I know you said "SQL", but you could have been
talking about the language, instead of SQL Server.)

When you reply, please set Follow-ups to the relevant newsgroup.

Bob Barrows


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Jos
Guest
Posts: n/a
 
      01-26-2004
Jon Davis wrote:
> Try this C#:
>
> string yesterday = DateTime.Now.AddDays(-1).ToString();
> string now = DateTime.Now.ToString();
> string sSQL = "SELECT * FROM FIELD "
> + "WHERE DATE > '" + yesterday + "' AND DATE <= '" + now +
> "'";
>
> Untested; might be a minor syntax typo but your compiler should catch
> it. For instance, I don't remember if dates are 'date' or %date%.


Also note that this code will only work on clients configured for
the American English region.
If the client is configured for another region, than
now and yesterday will be formatted accordingly,
while the SQL string always needs to be in the mm-dd-yy format.

Therefore, it is better to use parameters in the SQL string:

string sSQL = "SELECT * FROM FIELD " +
"WHERE DATE > @date1 AND DATE <= @date2;"
SqlCommand cm = new SqlCommand(sSQL, conn);
cm.Parameters.Add("@date1",yesterday);
cm.Parameters.Add("@date2",now);

--

Jos Branders


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date::Manip hours elapsed not business hours elapsed rutherf Perl Misc 2 10-28-2006 08:05 AM
1700 series: S0 is up 2 hours, down 2 hours, up, down, arghgh! Ivan Cisco 11 10-14-2004 08:41 AM
ASP DATE between NOW and 24 HOURS earlier. Darren ASP .Net 3 01-26-2004 09:22 AM
ASP DATE between NOW and 24 HOURS earlier. Darren ASP .Net Web Services 3 01-26-2004 09:22 AM
Hi im going to make a "time counter" from hours to hours and a loggfile export system Rahmi Acar C++ 0 07-17-2003 08:28 PM



Advertisments