Skip to content
Advertisement

Tag: date

Loop through all months in a date range?

If I have a start date (say 2009-02-01) and an end date (say 2010-01-01), how can I create a loop to go through all the dates (months) in the range? Answer Try Mind the note http://php.net/manual/de/datetime.formats.relative.php Relative month values are calculated based on the length of months that they pass through. An example would be “+2 month 2011-11-30”, which would

How to generate random date between two dates using php?

I am coding an application where i need to assign random date between two fixed timestamps how i can achieve this using php i’ve searched first but only found the answer for Java not php for example : Answer PHP has the rand() function: It also has mt_rand(), which is generally purported to have better randomness in the results: To

Increase days to php current Date()

How do I add a certain number of days to the current date in PHP? I already got the current date with: Just need to add x number of days to it Answer php supports c style date functions. You can add or substract date-periods with English-language style phrases via the strtotime function. examples… or

How do I use PHP to get the current year?

I want to put a copyright notice in the footer of a web site, but I think it’s incredibly tacky for the year to be outdated. How would I make the year update automatically with PHP 4 or PHP 5? Answer You can use either date or strftime. In this case I’d say it doesn’t matter as a year is a year,

Advertisement