CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    ASP searching databse for date part

    Hi,

    I am working on a genealogy website and want to display on the home page a "on the day" function. I have worked out different methods to extract the date and month from current time with which to query the access database. Here I have become hoplessly stuck, this is the cose I am using:

    Code:
    DIM PartDay, PartMonth, ThisDay
    PartDay = DatePart("d", Date())
    PartMonth = DatePart("m", Date())
    ThisDay = PartDay & PartMonth
    
    Set objRS = Server.CreateObject("ADODB.Recordset") 
    MySQL = "SELECT * from Diary where Date Like '#" & ThisDay & "#'" 
    objRS.Open MySQL, objConn, 1, 3
    i have also tried another variation querying the database with 23/03 but still no joy.

    Please can somebody please tell me how to query a database date

    Thank you
    Last edited by PeejAvery; March 23rd, 2009 at 10:18 AM. Reason: Added code tags.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: ASP searching databse for date part

    Don't use LIKE with a date. Simply query the date as equal to string.

    If the column is DATE type...
    Code:
    "SELECT * FROM Diary WHERE Date = 'YYYY-MM-DD'"
    If the column is DATETIME/TIMESTAMP type...
    Code:
    "SELECT * FROM Diary WHERE Date = 'YYYY-MM-DD HH:MM:SS'"
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Smile Re: ASP searching databse for date part

    Thank you for your reply but I don't think I made my predicament clear enough in my original post.

    I am trying to search for a part date for example 24 March or 24/03

    so that this will then retrieve every matching date in any year.

    Thanks again

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: ASP searching databse for date part

    So, you still apply my same principle of SQL query, then add the LIKE statement.

    Code:
    "SELECT * FROM Diary WHERE Date LIKE '%-MM-DD'"
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured