Saturday, 18 May 2013 13:56

how to extract day,month,year values from date string input in php

Written by 
Rate this item
(2 votes)

there are many ways to take date input in php.here
is a simple way to take date input as string and
extract the individual parts of the date as day,
month,year values.this values can be used for
different purposes -

suppose you have taken the date input in a form
by the following way using html -

Date of Birth (mm/dd/yy)<br><input type="text"
name="dob" size="8" maxlength="8" class="txt">

after the form have been submitted and dob was
past as POST data,extract the individual parts
of the date.first make use of the explode function
as follows-

array = explode("/", $dob);
$dobmonth = $array[0];
$dobday = $array[1];

if ($array[2] > 80)
$dobyear = "19" . $array[2];

else
$dobyear = "20" . $array[2];
$fdob = "$dobyear-$dobmonth-$dobday";

here the individual parts were extracted
as dobyear,dobmonth,dobday.

Read 53058 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.