Skip to content
Advertisement

Tag: date

How to get closest date compared to an array of dates in PHP

This post almost answered this question for me, but I have a specific need and didn’t find what I sought there. This lies right outside my experience; couldn’t quite wrap my head around it, so all I really need is a point in the right direction. Let’s say I have an array as follows: I would like to have a

Get previous week number from php week number

I currently need to get the previous week from a variable that passes a php week number so if it is week 13 I will get week 12. The problem I am facing is that if I just minus 1 from the original number if I am in week 1 it will return week 0 unless I create an if

Add six months in php

I’m trying to get the month, six months out from the current date. I’ve tried using: date(‘d’, strtotime(‘+6 month’, time())); But it doesn’t seem to work, always returns 01. Is there a better way to do this? Thank you! Answer I find working with DateTime much easier to use: or or in PHP version 5.4+

Calculate the number of months between two dates in PHP?

Without using PHP 5.3’s date_diff function (I’m using PHP 5.2.17), is there a simple and accurate way to do this? I am thinking of something like the code below, but I don’t know how to account for leap years: I’m trying to work out the number of months old a person is. Answer You may want to include the days

Get date in Leap years php

I want to convert 59 to 2012-feb-29. I already know current year is 2012. I try following code. but it give 2012-mar-01. $string = ’59 2012′; $date1 = date_create_from_format(‘z Y’, $string); $…

php date validation

Im trying to to set up a php date validation (MM/DD/YYYY) but I’m having issues. Here is a sample of what I got: Answer You could use checkdate. For example, something like this: A more paranoid approach, that doesn’t blindly believe the input:

Javascript getTime to php date

I have javascript that turns dates in my view to a time string using getTime(). That then is stored as a value for an option in my select form. Once it is passed to php, how do I turn that into a php date? I have done: Answer You use PHP’s date() function: Updated, thanks Yoshi.

PHP, Date() and fopen

I have an error system that take the date() and the error and insert it into a file: My problem: for start at the fopen at the second parameter I need the pointer to be at the start and that looked at the manual and I need the parameter to be writing only, put the pointer at the start and

Advertisement