如何使用mysql

时间:2017-03-11 05:31:42

标签: mysql

enter image description here

嗨,大家好我想从这个场景获得当前记录,例如开始日期10-03-2018到11个月,然后上一个日期是10-02-2019从这个持续时间。

4 个答案:

答案 0 :(得分:1)

试试这个

<?php
$date = date('Y-m-d'); //2017-03-14
$finaldate= date('Y-m-d', strtotime("+11 months", strtotime($date)));
$select_query = "SELECT * 
FROM tablename
WHERE date >  '".$finaldate."'";
?>

答案 1 :(得分:0)

这是你对mysql的SQL查询:

App app = new App();
        app.onCreate();

        app.getLanguageDetectionApi().getData("4978e60252ae102dfe1341146bb8cc3ec4bbbd78", textForRecognition).enqueue(new Callback<List<PostModel>>() {
            @Override
            public void onResponse(Call<List<PostModel>> call, Response<List<PostModel>> response) {
                List<PostModel> posts = new ArrayList<>();
                posts.addAll(response.body());
            }

            @Override
            public void onFailure(Call<List<PostModel>> call, Throwable t) {
                Toast.makeText(MainActivity.this, "An error occurred during networking", Toast.LENGTH_SHORT).show();
            }
        });

根据您的数据库更改您的表名和列名

您可以根据您的月,年或日进行更改

答案 2 :(得分:0)

您可以使用其他方式执行此操作,例如

$startdate = date('Y-m-d H:i:s',$your_date);
SELECT date,start_date,CONCAT('INTERVAL ',number_of_months,' ','MONTH') as comapre_date FROM table_name having date BETWEEN start_date AND (start_date - comapre_date)

尝试使用此查询希望这会有效..

答案 3 :(得分:0)

SELECT * FROM `extend_blog_details` as ExtendBlogDetail WHERE item_id='$item_id' and CURDATE() between start_date and DATE_ADD(start_date,INTERVAL TIMESTAMPDIFF(MONTH,NOW(),DATE_ADD(start_date, INTERVAL `number_of_months` month)) month) limit 1

我从此查询中获得了当前记录