I have dates in the following format (yyyymmdd, 18751104, 19140722)… what’s the easiest way to convert it to date()…. or is using mktime() and substrings my best option…?
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
The first day of the current month in php using date_modify as DateTime object
I can get the Monday of this week with: I would like to get with the same ease the 1st of this month. How can I achieve that? Answer Requires PHP 5.3 to work (“first day of” is introduced in PHP 5.3). Otherwise the example above is the only way to do it: In PHP 5.4+ you can do this:
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,