English 中文(简体)
日期日期功能功能
原标题:date functionality
  • 时间:2012-05-21 15:46:42
  •  标签:
  • date
  • php

我想打印一个特定日期的7天。 我尝试阅读了php 手册, 尝试了几件事情。

<?php
function add_date($givendate,$day=0,$mth=0,$yr=0) {
      $cd = strtotime($givendate);
      $newdate = date( Y-m-d h:i:s , mktime(date( h ,$cd),
                                            date( i ,$cd), 
                                            date( s ,$cd), 
                                            date( m ,$cd)+$mth,
                                            date( d ,$cd)+$day, 
                                            date( Y ,$cd)+$yr));
      return $newdate;
}

?>

但除今天的约会外,这绝不是给我任何日期的。

最佳回答

您可以使用 DateTime 类 :

例如:

$today = new DateTime("now");

$yesterday = $today->modify( -1 day );
$yesterday = get_object_vars($yesterday);
echo $yesterday[ date ]."<br>";

$twoDaysAgo = $today->modify( -1 day );
$twoDaysAgo = get_object_vars($twoDaysAgo);
echo $twoDaysAgo[ date ];
问题回答

暂无回答




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签