473,725 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3399
Try this C#:

string yesterday = DateTime.Now.Ad dDays(-1).ToString();
string now = DateTime.Now.To String();
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.Ad dDays(-1).ToString();
string now = DateTime.Now.To String();
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.A dd("@date1",yes terday);
cm.Parameters.A dd("@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
3341
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 should be used in a form so when opening the page, automatic all the
38
7160
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; } function makeArray0() {
17
25897
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 to provide a listing of all table entries between 22:00 and 07:30 the next day, between a given set of dates (typically one week apart but in practice between any dates specified). My query works ok for 1 date - entering 2 dates, one for 22:00 -...
3
1246
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 grasp. I am stuck getting the 24 hours earlier data capture. Thanks! Gary.
26
2721
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 to convert a latitude coord back to an accurate date time. Then I could detect the day/hour in the viewport when the timeline is zoomed in or out, or if it is moved. I cannot use the javascript date functions because this timeline will...
4
15751
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 which calculated the difference in years and days between two dates, and takes leap years into account? I'm calculating the difference in the usual way, i.e....
15
2335
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 in my code, as it does not seem to work? I am actually trying to learn what parts of the code do what and why, so if anyone can take the time to explain it would be much appreciated. Here is my script: <script language="javascript">
2
2712
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 up an arrival time and a departure time for the script. This is using AJAX (which I am such a newbee @) from my earlier post http://www.thescripts.com/forum/threadnav583131-1-10.html Any help is greatly appreciated. <? $output = '';
16
4457
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 22:02:51? (24 hour day is fine) How about the date after 02/28/04 is 02/29/04, or the date after 09/30/08 is 10/01/08?
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8099
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.