Stackoverflow community. Recently i just have unique experience. Been Google, trial and error for hours but still not find a solution for this. Input and desired output is actually pretty simple but tricky, i just dont know how to code it properly.
Well, i will define the requirement.
Explanation and Requirement :
- I have an input field. This input field type is MONTH (not DATE). So basically this input field should only produce year and month, different from DATE input type that will produce complete date.
- I want to echo value in this MONTH input field after converted to STRING before (example : "2016-7" in STRING format) and also produce something like "Jul 2016".
This MONTH format is similar like DATE format, but script that usually work with DATE format, not working with MONTH format. Thats make me wondering, im curious why.
For basic input type MONTH i use this script.
<input type="month" name="monthTransaction" value="<?php echo date("Y-m") ?>"/>
Then i tried something like this to echo it.
$month = mysql_real_escape_string($_POST['monthTransaction']);
$newmonth = date('Y-m', strtotime(str_replace('-', '/', $tr)));
echo $month; // Probably STRING format (i need further explanation)
echo $newmonth; // Probably DATE format (i need further explanation)
This is not working after all. But i tried this with input field with DATE type, its working. The echo fine with DATE type format.
From this code i learn that actually strtotime isn't convert DATE to string. I not know it well but it works well (can echo) with DATE format but not with MONTH format.
If you can tell me how to convert MONTH input type to STRING, it will be so great, because i can learn from that.
Desired Output :
- It will print in basic format like "2016-07"
- It will print in advanced format like "July 2016"
Second Question (Minus One Month From Input Value) :
Well it's actually another question that related with this.
Second Question Explanation and Requirement :
Second Question Desired Output :
- I actually want to get input value in MONTH input field minus one (-1) month from input value.
- So if you enter "2016-07" for example, it will give "2016-06" and so on.
DATE format is ordinary, but MONTH format seems challange me. Anybody know how to fix this ? As i said simple but tricky. Btw, thank you in advance.