473,395 Members | 1,730 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,395 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!
Jul 19 '05 #1
3 3391
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!

Jul 19 '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"
Jul 19 '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
Jul 19 '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...
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...
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...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.