dongzhi7641 2011-07-28 16:07
浏览 47
已采纳

格式化日期并使用php添加或减去来自mysql的日期天数

i am using mysql and and php , currently i have date and time in my database but when i get the date using sql , i keep on getting 1970-01-01 no matter what date , but if i try to add still no luck ! can any one guide me

 $startDate = $result['startDate'];
 $date=date('Y-m-d',$startDate);
 echo $date;

it should be something like 01-07-2011 . but it dosn't i have tried strtotime() also . but it dosnt help . can any one help me .

 $date = strtotime(date("Y-m-d", strtotime($startDate)) . " +1 day");
 echo $date;

answer should be 2011-07-02 but its 1970-01-02

thanks in advance

  • 写回答

4条回答 默认 最新

  • 普通网友 2011-07-28 16:14
    关注

    As long as $result['startDate'] is a date type column, and you're on a version of php greater than 5.0.2, you're looking for:

     $startDate = $result['startDate'];
     $date=date('Y-m-d',strtotime($startDate. ' +1 day'));
     echo $date;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动