473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

ASP DATE between NOW and 24 HOURS earlier.

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!
Nov 18 '05 #1
3 1239
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" <d@nospam.com> wrote in message
news:bd**********************@news-text.cableinet.net...
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!

Nov 18 '05 #2
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"
Nov 18 '05 #3
Jos
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
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jeroen | last post by:
Hi, I'm searching but not finding :( I need the code that creates automatic the days in a month So like for this month, it creates the days in this format 01-Oct, 02-Oct, .... This...
3
by: Darren | last post by:
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...
38
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
17
by: Lapchien | last post by:
My table has a record called date/time - filled (not surprisingly) with a date and time. I can format the date in one query field, also the time, using format in an expression. My user wants me...
26
by: jshanman | last post by:
I am writing a timeline that uses Google Maps. I have a function that converts a date time to latitude coords. This function is used to draw the markers on the timeline. I need a reverse function...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
15
by: Cerebral Believer | last post by:
Hi all, I am a newbie to JavaScript and am just trying to get a script going that will write the ful date and time to each webpage as it is viewed. Can anyone point out what mistakes there are...
2
cassbiz
by: cassbiz | last post by:
I am using strtotime and I have read up on some examples and am getting the wrong output, it jumps by several days instead of one day at a time. Ultimately what I am trying to accomplish is to set...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
16
by: W. eWatson | last post by:
Are there some date and time comparison functions that would compare, say, Is 10/05/05 later than 09/22/02? (or 02/09/22 format, yy/mm/dd) Is 02/11/07 the same as 02/11/07? Is 14:05:18 after...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.