Professional Web Applications Themes

ASP DATE between NOW and 24 HOURS earlier. - ASP Components

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!...

  1. #1

    Default 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!


    Darren Guest

  2. #2

    Default 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!


    Darren Guest

  3. #3

    Default 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!


    Darren Guest

  4. #4

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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" <dnospam.com> wrote in message
    news:bd_Qb.9794$jD6.104753317news-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!
    >
    >

    Jon Davis Guest

  5. #5

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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" <dnospam.com> wrote in message
    news:bd_Qb.9794$jD6.104753317news-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!
    >
    >

    Jon Davis Guest

  6. #6

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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" <dnospam.com> wrote in message
    news:bd_Qb.9794$jD6.104753317news-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!
    >
    >

    Jon Davis Guest

  7. #7

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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"


    Bob Barrows Guest

  8. #8

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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"


    Bob Barrows Guest

  9. #9

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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"


    Bob Barrows Guest

  10. #10

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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


    Jos Guest

  11. #11

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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


    Jos Guest

  12. #12

    Default Re: ASP DATE between NOW and 24 HOURS earlier.

    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


    Jos Guest

Similar Threads

  1. Earlier versions available?
    By MaryO26 in forum Macromedia Contribute General Discussion
    Replies: 0
    Last Post: May 15th, 12:18 AM
  2. What a pig's ear I've made of my earlier post
    By Alex Buell in forum MySQL
    Replies: 5
    Last Post: May 27th, 09:24 PM
  3. CS can't open AI10 files saved as earlier versions (9 and earlier)
    By kurt_triffet@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 0
    Last Post: February 27th, 12:04 AM
  4. [Q]how to display date after 24 hours?
    By gjo in forum Linux / Unix Administration
    Replies: 5
    Last Post: December 6th, 12:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139