![]() |
|
#1
|
|||
|
|||
date of YesterdayI want to create the date of yesterday for date entered. I got the date for yesterday as:
PHP Code:
but, if I enter day=6, month=10 year-2006, how can I get yesterday's date for above date? And how can I get the date for day before $yesterday? Last edited by LuciWiz : 28-Nov-2006 at 05:23.
Reason: Please insert your Php code between [php] & [/php] tags
|
|
#2
|
||||
|
||||
Re: date of YesterdayYou can easily get the date of yesterday by using strtotime().
Here are a couple of examples: PHP Code:
You can refer to http://www.gnu.org/software/tar/manu...19.html#SEC119 for examples of valid (relative) date strings that you can use with strtotime(). __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
Re: date of YesterdayIt uses the system date, but if I enter my own date for example: day=6, month = 10, year = 2006, how can I get the date for day before above date.
|
|
#4
|
||||
|
||||
Re: date of YesterdayIf you look at the details of the strtotime function, you will see that it expects an optional timestamp value too.
int strtotime ( string time [, int now] ) So, if you omit passing a timestamp in the second parameter, you will be expecting the results relative to the system date, as per my examples above. If you have your own timestamp, you can submit it to this second parameter and the calculations will be relative to this value, and not the system date. Here is a new example: PHP Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#5
|
||||
|
||||
Re: date of YesterdayYes, of course.
$mydate = '2006-10-01' is just a string. It could have been written like this as well: $mydate = "$year-$month-$day"; where $year is 2006, $month is 10 and $day is 6. |
|
#6
|
|||
|
|||
Re: date of YesterdayThank you so much, I've got the solution.
|
|
#7
|
||||
|
||||
Re: Get yesterday's dateOne last thing, reading the page again, I found this important detail.
Quote:
Emphasis mine. So, '2006-10-01' is correct and '2006-10-1' is not!? |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with Overloaded Constructors and Class within Class | jdbrine | CPP / C++ Forum | 2 | 10-Jul-2006 22:14 |
| Current Date (Short Date) In C | Vishy80 | C Programming Language | 2 | 07-Jun-2005 13:54 |
| Limit combo box and date time picker choice according to database created in folder | shinyhui | CPP / C++ Forum | 0 | 22-Feb-2005 20:16 |
| Limit combo box and date time picker choice according to database created in folder | shinyhui | MS Visual C++ / MFC Forum | 0 | 22-Feb-2005 02:13 |
| Rookie problem with date format | cave monkey | MySQL / PHP Forum | 4 | 18-Mar-2004 08:41 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The