Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    ASP help with SQL and dates

    Hey everyone, I am currently working on a project in ASP.

    Ive been doing PHP for nearly 5 years now, and this is the first time i will be using ASP.

    Im having a problem with the SQL.

    You see, i have a table where i have some fields which include startdate and enddate which are dates.

    I wish to extract the data which are valid for a particular day.

    for example:

    Query = "SELECT * FROM table WHERE enddate>today AND startdate<today"

    where today = todays date....

    But i cannot do it, can anyone help or point me in the right direction?

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Query = "SELECT * FROM table WHERE enddate>'" & Date() & "' AND startdate< '" & Date() & "'"

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What database are you using?

    You can get the date function for the database from the help files.

    SQL Server
    Code:
    Query = "SELECT * FROM table WHERE enddate > getDate() AND startdate < getDate()"
    Access
    Code:
    Query = "SELECT * FROM table WHERE enddate > Now() AND startdate < Now()"

  • #4
    Regular Coder Baleric's Avatar
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    332
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by degsy View Post
    What database are you using?

    Access
    Code:
    Query = "SELECT * FROM table WHERE enddate > Now() AND startdate < Now()"
    'Now()' will returnt he date and time together,

    i think he need to use 'Date()'

  • #5
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    For Access, following code is better:

    Code:
    Query = "SELECT * FROM table WHERE enddate > Date() AND startdate < Date()"
    -SSJ


  •  

    Posting Permissions

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