1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to only show the 10 days info from MySQL table?

Discussion in 'C#' started by JJnacy, Aug 20, 2009.

  1. #1
    I only want to select recently 10 days data.

    select * from TB1 where ?

    what is the asp script

    Thanks
    SEMrush
     
    JJnacy, Aug 20, 2009 IP
    SEMrush
  2. web-bod

    web-bod Guest

    Messages:
    17
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if you gave us a clue about the columns in the table we might be able to help
     
    web-bod, Aug 20, 2009 IP
  3. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,607
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #3
    select * from TB1 where DATEFIELD > 'NOW - 10 DAYS';

    Replace datefield with the field that has the date, and you can fill in between the '' with the ASP datecompare code now - 10 day :)
     
    ccoonen, Aug 20, 2009 IP
    JJnacy likes this.
  4. JJnacy

    JJnacy Peon

    Messages:
    448
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks,

    But your SQL I used

    It is very strange.
    it worked for MSsql but not worked for MySQL

    for MySQL
    it still shows example 8/1/2009 5:42:23 AM info


    Does it mean datetime settings are different for MsSQL and MySQL?

    I still need helps.
     
    JJnacy, Aug 21, 2009 IP
  5. vihutuo

    vihutuo Well-Known Member

    Messages:
    1,511
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    130
    #5
    In MYSQL

    DATEFIELD > DATE_ADD(CUR_DATE(),INTERVAL -10 DAY)
    PHP:
     
    vihutuo, Aug 23, 2009 IP
  6. sibangor

    sibangor Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    select * from table where datefield between @startdate and @enddate
     
    sibangor, Aug 28, 2009 IP
    JJnacy likes this.
  7. JJnacy

    JJnacy Peon

    Messages:
    448
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks but the SQL still not work for [ ASP classic + MySQL ]

    Still need other solution.
     
    JJnacy, Aug 29, 2009 IP
  8. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    What is the data type of the date field? Is it just a text or varchar, or is it date (or datetime). If it is just text or varchar, I don't believe there is no way to do date functions on the data. My understanding is the field would have to be in a date (or datetime) format.

    For my datetime fields in Classic ASP and MySQL, I use
    SELECT * FROM TableName WHERE DATE_SUB(CURDATE(),INTERVAL 10 DAY) <= DateFieldName

    This would grab all records for 10 days, up to and including today's date.
     
    nyxano, Aug 29, 2009 IP
  9. JJnacy

    JJnacy Peon

    Messages:
    448
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Please tell me where to put DateFieldName

    Is this one?
    SELECT * FROM TableName WHERE DateFieldName > DATE_SUB(CURDATE(),INTERVAL 10 DAY)
     
    JJnacy, Aug 30, 2009 IP
  10. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #10
    SELECT * FROM TableName WHERE DATE_SUB(CURDATE(),INTERVAL 10 DAY) <= DateFieldName

    Replace "TableName" with the name of your Table, and replace "DateFieldName" at the end when the name of your Date Field. This will get you the last 10 Days of records from the Current Date. So if the date is August 30, this will give you all records from August 21 to August 30 - 10 days.
     
    nyxano, Aug 30, 2009 IP