javascript - Separating date and month from the given date

171

I've created a text-box where I'm binding date and year. This is how I've done:

jQuery("#year_month").datetimepicker({ format: 'YYYY-MM' });

This is how I receive in php:

$year_month = mysqli_real_escape_string($mysqli, $_REQUEST["year_month"]);

Here I have to separate the year and month. How can I do that?

941

Answer

Solution:

try useexplode() function:

<?php

$example_string = "2016-05-12 16:27:11: 2016-05";

list($year, $month) = explode("-", substr($example_string, 0, 7));

echo $year . "\n";
echo $month;

output:

2016
05

People are also looking for solutions to the problem: php - How can I sort the results of a for each loop?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.