0

I am writing a php application which is using a MS SQL database and I have the following code:

$nextdue = date('Y-m-j', strtotime('+'.$validity.' months', strtotime($issuedate)));

The purpose of the code is to add a number of months to a document issue date to calculate an expiry date. For the purpose of this query, the validity period looks up the document type and returns the number of valid months for that particular document - I know this is working. I have used this code before for a PHP and MySQL database and it worked just fine. I am assuming I have missed something in the way MS SQL stores date format?

When I have an issue date of 19/05/2022 (dd/mm/yyyy), it is adding 36 months to it and then returning a value of 01/01/1979 - which is clearly wrong.

Can anyone help me out please?

Also I have done a var_dump for issue date which returns as

IssueDate:19 \ / 05 \ / 2022

  • `Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-), the date string is parsed as y-m-d.` Your format is d/m/y, which is not what it's expecting. You'll need to use the DateTime class to parse it properly. – aynber May 19 '22 at 13:13

0 Answers0