<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Date format validation in PHP</title>
	<atom:link href="http://roshanbh.com.np/2008/05/date-format-validation-php.html/feed" rel="self" type="application/rss+xml" />
	<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html</link>
	<description>Useful Tutorials, Scripts , Tips, and Resources for all PHP and Ajax beginners and experts .</description>
	<lastBuildDate>Tue, 07 Feb 2012 08:10:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: decade</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-6559</link>
		<dc:creator>decade</dc:creator>
		<pubDate>Fri, 24 Jun 2011 09:48:40 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-6559</guid>
		<description>damn this i use your preg_match and it give an error so i modify it into more simple code :

checkDateFormat($date){
	if(preg_match(&quot;/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/&quot;, $date)){
		return true;
	}else{
		return false;
	}
}</description>
		<content:encoded><![CDATA[<p>damn this i use your preg_match and it give an error so i modify it into more simple code :</p>
<p>checkDateFormat($date){<br />
	if(preg_match(&#8220;/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/&#8221;, $date)){<br />
		return true;<br />
	}else{<br />
		return false;<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pooja</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-5450</link>
		<dc:creator>pooja</dc:creator>
		<pubDate>Tue, 18 May 2010 09:14:49 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-5450</guid>
		<description>hello.. i am trying to fetch datetime from a text.... can any one help me how can i do this using regular expression preg_match????


Thnaks....</description>
		<content:encoded><![CDATA[<p>hello.. i am trying to fetch datetime from a text&#8230;. can any one help me how can i do this using regular expression preg_match????</p>
<p>Thnaks&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-4010</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Sun, 24 May 2009 10:20:32 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-4010</guid>
		<description>Thanks</description>
		<content:encoded><![CDATA[<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-4008</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Fri, 22 May 2009 23:07:31 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-4008</guid>
		<description>ps the above preg only accept years 2000 - 2099, you need to adjust this for your preferences</description>
		<content:encoded><![CDATA[<p>ps the above preg only accept years 2000 &#8211; 2099, you need to adjust this for your preferences</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-4007</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Fri, 22 May 2009 23:02:38 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-4007</guid>
		<description>Here is a function if you have a string of dates that need to be validated. I also need to pick off the last date, thats why it is sorted. This is a pretty strict function obviously you can tone it down to your needs, most could probably do without checkdate since most date errors will be caught in the preg, and of course you probably don&#039;t need a sort.

function checkDateFormat(&amp;$data){
preg_match_all(&#039;/(20\d{2})\/(0[1-9]&#124;1[012])\/(0[1-9]&#124;[12]\d&#124;3[01])/&#039;, $data, $matches, PREG_SET_ORDER);
$orderDates=array();
for ($i = 0; $i &lt; count($matches); $i++) {
if(checkdate($matches[$i][2],$matches[$i][3],$matches[$i][1])){
$orderDates[]=strtotime($matches[$i][0]);
}
}
sort($orderDates);
$output=false;
for ($i=0;$i&lt;sizeof($orderDates);$i++) {
if ($i!=0) {
$output.= &#039;,&#039;;
}
$output.= date(&#039;Y/m/d&#039;,$orderDates[$i]);
}
if($output){
return $output;
} else {
return false;
}
}
$str = &#039;2008/02/29,2007/02/29,2004/07/07,2035/13/00,2005/04/25&#039;; // 2008 was a leap year
echo checkDateFormat($str);</description>
		<content:encoded><![CDATA[<p>Here is a function if you have a string of dates that need to be validated. I also need to pick off the last date, thats why it is sorted. This is a pretty strict function obviously you can tone it down to your needs, most could probably do without checkdate since most date errors will be caught in the preg, and of course you probably don&#8217;t need a sort.</p>
<p>function checkDateFormat(&amp;$data){<br />
preg_match_all(&#8216;/(20\d{2})\/(0[1-9]|1[012])\/(0[1-9]|[12]\d|3[01])/&#8217;, $data, $matches, PREG_SET_ORDER);<br />
$orderDates=array();<br />
for ($i = 0; $i &lt; count($matches); $i++) {<br />
if(checkdate($matches[$i][2],$matches[$i][3],$matches[$i][1])){<br />
$orderDates[]=strtotime($matches[$i][0]);<br />
}<br />
}<br />
sort($orderDates);<br />
$output=false;<br />
for ($i=0;$i&lt;sizeof($orderDates);$i++) {<br />
if ($i!=0) {<br />
$output.= &#8216;,&#8217;;<br />
}<br />
$output.= date(&#8216;Y/m/d&#8217;,$orderDates[$i]);<br />
}<br />
if($output){<br />
return $output;<br />
} else {<br />
return false;<br />
}<br />
}<br />
$str = &#8217;2008/02/29,2007/02/29,2004/07/07,2035/13/00,2005/04/25&#8242;; // 2008 was a leap year<br />
echo checkDateFormat($str);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bogdan</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-3938</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Tue, 05 May 2009 18:10:29 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-3938</guid>
		<description>Can anyoane help me to validate a date and time field? The format is yyyy-mm-dd HH:mm:ss (ex: 2009-05-18 20:59:50)

Thanks</description>
		<content:encoded><![CDATA[<p>Can anyoane help me to validate a date and time field? The format is yyyy-mm-dd HH:mm:ss (ex: 2009-05-18 20:59:50)</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ben</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-3611</link>
		<dc:creator>ben</dc:creator>
		<pubDate>Wed, 25 Feb 2009 17:13:57 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-3611</guid>
		<description>if (preg_match (”/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/”, $date, $parts))
{
if(checkdate($parts[2],$parts[1],$parts[3]))
return true;
else
return false;
}


in reply to the above poster, to make this function work you will need to slash out the slashes to make PHP recognise them... this will work...

if (preg_match (”/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/”, $date, $parts))
{
if(checkdate($parts[2],$parts[1],$parts[3]))
return true;
else
return false;
}


Hope this helps!</description>
		<content:encoded><![CDATA[<p>if (preg_match (”/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/”, $date, $parts))<br />
{<br />
if(checkdate($parts[2],$parts[1],$parts[3]))<br />
return true;<br />
else<br />
return false;<br />
}</p>
<p>in reply to the above poster, to make this function work you will need to slash out the slashes to make PHP recognise them&#8230; this will work&#8230;</p>
<p>if (preg_match (”/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/”, $date, $parts))<br />
{<br />
if(checkdate($parts[2],$parts[1],$parts[3]))<br />
return true;<br />
else<br />
return false;<br />
}</p>
<p>Hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anand Acharya</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-3213</link>
		<dc:creator>Anand Acharya</dc:creator>
		<pubDate>Tue, 25 Nov 2008 05:35:40 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-3213</guid>
		<description>how to validate date in (dd/mm/yyyy) format ? 
i have tried your function with 

if (preg_match (&quot;/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/&quot;, $date, $parts))
{
  if(checkdate($parts[2],$parts[1],$parts[3]))
    return true;
  else
    return false;
}


but is gives an error Unknown modifier &#039;(&#039; in preg_match</description>
		<content:encoded><![CDATA[<p>how to validate date in (dd/mm/yyyy) format ?<br />
i have tried your function with </p>
<p>if (preg_match (&#8220;/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/&#8221;, $date, $parts))<br />
{<br />
  if(checkdate($parts[2],$parts[1],$parts[3]))<br />
    return true;<br />
  else<br />
    return false;<br />
}</p>
<p>but is gives an error Unknown modifier &#8216;(&#8216; in preg_match</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roshan</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-845</link>
		<dc:creator>Roshan</dc:creator>
		<pubDate>Tue, 13 May 2008 10:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-845</guid>
		<description>You can&#039;t rely on the validation of javascript, as it can be bypassed by disabling javascript in browser and that function was working perfectly for various supplied data......can you please post the dates from which you&#039;ve got bad or wrong result..</description>
		<content:encoded><![CDATA[<p>You can&#8217;t rely on the validation of javascript, as it can be bypassed by disabling javascript in browser and that function was working perfectly for various supplied data&#8230;&#8230;can you please post the dates from which you&#8217;ve got bad or wrong result..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suresh</title>
		<link>http://roshanbh.com.np/2008/05/date-format-validation-php.html/comment-page-1#comment-839</link>
		<dc:creator>Suresh</dc:creator>
		<pubDate>Mon, 12 May 2008 19:09:12 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/?p=105#comment-839</guid>
		<description>I used checkdate() to validate date in format &#039;YYYY-mm-dd&#039; . but i can&#039;t able to get the expect result . Now i am using Javascript to validate date.</description>
		<content:encoded><![CDATA[<p>I used checkdate() to validate date in format &#8216;YYYY-mm-dd&#8217; . but i can&#8217;t able to get the expect result . Now i am using Javascript to validate date.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/15 queries in 0.008 seconds using disk: basic
Object Caching 327/328 objects using disk: basic

Served from: roshanbh.com.np @ 2012-02-09 05:38:51 -->
