|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
php5 - Quick question about strftime.
How do I display the following:
Current date - 1 day (yesterday's date) Current date - 2 days (the date of the day before yesterday) Current date - 3 days (the date of 3 days ago) Current date - 4 days (the date of 4 days ago) I already went through the PHP.net manual, but I do not understand how to achieve this. I just want to display the dates from 1, 2, 3 or 4 days ago on my website... |
|
#2
|
|||
|
|||
|
strtotime() is probably the easiest. takes a string and tries to calculate in a timestamp what the string is saying.
PHP Code:
|
|
#3
|
|||
|
|||
|
Great, exactly what I was looking for.
Why does it always look so easy to pull of?! Thnx once again! //edit One problem, now my months are in English and I want them to be in Dutch? That's why I was using strftime (nl_NL). How can I display the months in Dutch with your example? Last edited by HHawk : October 23rd, 2009 at 04:00 AM. |
|
#4
|
|||
|
|||
|
strftime has an opposite function strptime that takes a string formatted with strftime and the format string used in strftime and converts it to an array with all the time parts (day, month, year, hour...etc) which can be easily converted back to a timestamp with mktime(). However, strptime() is not implemented on windows yet so you would have to be using a *nix based OS. On windows, you would have to make your own function to get the date back. You can check out some of the user notes on the strptime manual page and there might be something that could work. Other than that, you can also do a simple string replace on the string to change the months to english months before using strtotime().
|
|
#5
|
|||
|
|||
|
Quote:
I am using a Plesk with *nix OS. |
|
#6
|
|||
|
|||
|
well then you should be able to use strptime() with no problems. something like:
PHP Code:
I don't have a *nix station at work to test, but that should work. You could probably wrap most of that in a function where you pass the format, time string from the original strftime and the string input for strtotime (ie +1 day) and it returns the modified new strftime string. |
|
#7
|
|||
|
|||
|
Quote:
Thnx man, I will give that a go. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > php5 - Quick question about strftime. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|