dongmo6937 2015-10-04 10:50
浏览 31

今天如何在DATE附近创建函数 - PHP

I have this variable:

$today = date("Y-m-d H:i:s"); // for example today is 2015-10-04 12:30:00
$first_date = "2015-10-01 00:00:00";
$second_date = "2015-10-02 00:00:00";
$third_date = "2015-10-03 00:00:00";
$fourth_date = "2015-10-04 00:00:00";
$fift_date = "2015-10-06 00:00:00";

//place the function - and result to $output $output = "result";

And I need this. If variable of any day is the nearliest to $today from PAST date, set $output = 1; ... If date is in BEFORE $today - ignor thi variable.

Anyone know?

For better understanding - I have a DATE in database like this in rows:

  1. ID_product = 4; ID_special_price = 20; from = 2015-10-03 00:00:00; to = 2017-04-30 00:00:00;
  2. ID_product = 4; ID_special_price = 21; from = 2015-10-03 00:00:00; to = 2015-10-04 00:00:00;
  3. ID_product = 4; ID_special_price = 22; from = 2015-10-04 00:00:00; to = 2015-10-05 00:00:00;
  4. ID_product = 4; ID_special_price = 23; from = 2015-10-05 00:00:00; to = 2015-10-07 00:00:00;

So this is a special price from(start) and to(end). In my case, I need to foreach ID_product 4 times and pick up only one row - now it will be row number 3. with ID_special_price = 22, becose this DATE - from(2015-10-04 00:00:00) today (2015-10-04 12:30:00) to(2015-10-05 00:00:00) is the nearest "to" actually date and still active, becose end of this special offer ending 2015-10-05 00:00:00.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制