Sid Sid - 1 year ago 92
MySQL Question

How to get digits from the date in php?

I am storing the date in varchar format in database. I want to get the 8 digits number from the input date. Input date can be in any format like 28/08/2016 , 28-08-2016 or 28 Aug 2016 etc.

Now I tried to do this:

$country = mb_substr($this->country, 0, 4);
$username = $this->user_name;
$converted_date = date('Y_m_d-H-i-s', strtotime($this->date_of_application));
$this-> member_id = $country.$username.$converted_date;

I am concatenating strings and the date. So my input date is :
28/08/2016 and output I am getting is: 1970_01_01-04-00-00

I changed the timezone in php.ini file.

So I want the output as number 28082016. How Can I get this?

Answer Source

'Y_m_d-H-i-s' is the format for the date. so if you want to concatenate the date to 28082016 this should do that:

$converted_date = date('dmY', strtotime($this->date_of_application));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download