1

I want to check a date exist or not with all format PHP like d-m-Y or jS-F-Y or D-M-Y ... ?

For example:

01-01-2018 => true
31-02-2018 => false
30 Februari 2018 => false
31st Feb 2018 => false
31st March 2018 => true
31-04-2018 => false

I found this function: checkdate but it only can check date with number format.

Mít
  • 195
  • 1
  • 3
  • 18
  • 3
    Possible duplicate of [Correctly determine if date string is a valid date in that format](https://stackoverflow.com/questions/19271381/correctly-determine-if-date-string-is-a-valid-date-in-that-format) – zero323 Jan 03 '18 at 13:18
  • You need to validate against predefined set of formats. You cannot use some formats simultaneously, because you would lose precision - for example 5-6-12 could mean 3 valid dates: 2005-06-12, 05-06-2012, 06-05-2012 (as in May 6th, 2012). – shudder Jun 08 '18 at 08:54

1 Answers1

0

You can go through the examples overhere

http://php.net/manual/en/function.checkdate.php

<?php
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));
?>

The above example will output:

bool(true) bool(false)

var_dump(validateDate('Tue, 28 Feb 2012 12:12:12 +0200', DateTime::RSS)); # true
var_dump(validateDate('Tue, 27 Feb 2012 12:12:12 +0200', DateTime::RSS)); # false

function was copied from this answer or php.net

Glavić
  • 42,781
  • 13
  • 77
  • 107