首页 > 解决方案 > 如何将日期字段设置为 3 个月前

问题描述

我正在使用单选按钮从数据库中获取最近 3 个月的记录。我正在使用单选按钮让用户选择三个月前的日期范围。如何将单选按钮的值设置为大约 3 个月前?

 <input type="radio" id="test7" name="thismonth" value="<?php echo date("Y-m", strtotime("-3 months"));?>" />

这将值设置为仅一个月,但有没有办法将值设置为恰好三个月前?

标签: phpmysql

解决方案


    <?php 
    $value = $_POST["thismonth"];

// note : name attribute for your input field is 'thismonth', should be something else.

    $query = "SELECT *columns* FROM *table* WHERE *date_column* BETWEEN '".$value."' AND '".date('Y-m')."' ";
    ?>

推荐阅读