MySQL Date将间隔添加为列表

时间:2015-06-30 20:39:08

标签: mysql date

有一个包含这样字段的表:(id,date,intervaldays) 而作为一个例子,日期=' 2015-06-30'间隔天数= 3 什么是列出所有日期(日期 - (日期+间隔日期))的查询,如果有的话,输出将如下:

    $csv = array_map('str_getcsv', file('upc.csv'));
    $count = count($csv) - 1;

    $i = '0';
    while($i <= 2){
    $data_upc = $csv[$i][0];

    $curl = 'site.com'.$data_upc.'#colors';
    $ch = curl_init($curl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36');
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    // No certificate
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);     // Follow redirects
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);             // Limit redirections to four
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    preg_match('/<a href="\/assets\/hlr-system(.*?)</',$response,$match);

    $pdf_url = $match[1];

    $pdf_url = 'beginning-url'.str_replace('" class="pdf">Spec Sheet','',$pdf_url);

    $pdf = 'brand/'.$data_upc.'.pdf';
    file_put_contents($pdf, fopen($pdf_url));


    echo 'testing: '.$pdf_url;
    echo '<br />';

    $i++;

    }

我记得DATE_ADD(日期,INTERVAL间隔日DAY)会给出最后一个日期,所以如何列出之间的日期

1 个答案:

答案 0 :(得分:0)

其实感谢@Mark Ba​​nnister this post 我提出了这个完美运行的查询

select selected_date from 
mytable JOIN 
(select adddate('1970-01-01',t4*10000 + t3*1000 + t2*100 + t1*10 + t0) selected_date from
 (select 0 t0 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
 (select 0 t1 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
 (select 0 t2 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
 (select 0 t3 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
 (select 0 t4 union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4
 ) v
 ON v.selected_date >= start_date AND v.selected_date<=DATE_ADD(start_date, INTERVAL days_interval DAY)

有任何改进吗?