Return Yesterdays Sales

Discussion in 'PHP' started by adamjblakey, Oct 4, 2010.

  1. #1
    Hi,

    I have a table with all my sales from yesterday. In the field i have the date of the order stored in this format: 1286193719

    I want to run a statement on the database to find all the sales from yesterday.

    I thought this would work:

    "SELECT fTotalPrice FROM te5_tbShop_Orders WHERE tmOrderDate = CURRENT_DATE() - INTERVAL 1 DAY"
    PHP:
    or

    "SELECT fTotalPrice FROM te5_tbShop_Orders WHERE date(tmOrderDate) = CURRENT_DATE() - INTERVAL 1 DAY"
    PHP:
    But it returns 0 even though there are 20 sales yesterday.

    Please can someone advise?

    Cheers,
    Adam
     
    adamjblakey, Oct 4, 2010 IP
  2. imperialDirectory

    imperialDirectory Peon

    Messages:
    395
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Looks like your date is in Unix Epoch time format. You will need to specific a time range to look for data from yesterday. Here's a sample you can try
    
    $yesterday = strtotime(strftime('%Y-%m-%d', time() - 86400));
    'SELECT fTotalPrice FROM te5_tbShop_Orders WHERE tmOrderDate >= ' . $yesterday . ' AND tmOrderDate <= ' . ($yesterday + 86399);
    
    Code (markup):
    Hope this helps.
     
    imperialDirectory, Oct 4, 2010 IP
  3. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Hi, you can try and the following :
    $query = "SELECT fTotalPrice FROM te5_tbShop_Orders 
    WHERE DATE(tmOrderDate) = DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)";
    PHP:
    Regards :)
     
    koko5, Oct 4, 2010 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Following shall do the trick:

    
    $day_start_time = mktime(0, 0, 0) - 86400;
    $day_end_time = mktime(0, 0, 0) - 1;
    $query = "SELECT fTotalPrice FROM te5_tbShop_Orders WHERE tmOrderDate BETWEEN $day_start_time AND $day_end_time"
    
    PHP:
     
    mastermunj, Oct 4, 2010 IP
  5. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Thank you for all your answers i got it working with a reply so big thanks.

    I have another issue which i am unsure about, now i have this working i need another query to run which goes through the previous month and gives me a report for each day. Any idea how i would do this?
     
    adamjblakey, Oct 11, 2010 IP