首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何获取两个日期之间的所有日期并插入到数据库中?

如何获取两个日期之间的所有日期并插入到数据库中?
EN

Stack Overflow用户
提问于 2018-06-21 05:05:20
回答 3查看 223关注 0票数 0

我正在尝试获取两个日期之间的所有日期,并将它们全部插入到一个表中。我怎样才能做到这一点呢?

代码语言:javascript
复制
    //current date
    $currentDate = date('Y-m-d');

    //find next monday from current date
    $nextMonday = date('Y-m-d', strtotime('next monday', strtotime($currentDate)));   

    //get last day of current year
    $yearEnd = date('Y-m-d', strtotime('12/31'));

   //get all dates between nextMonday and yearend
   [...]

 foreach ($period as $dateCreated) {
   //insert the dates in db
    $stmt = $conn->prepare("INSERT INTO user_schedule (userId,dateCreated) VALUES (?,?)");
    $stmt ->bind_param('is',$userid,$dateCreated);
    $stmt ->execute();
    $stmt ->close();
 }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50957009

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档