mysql - HTML5 & PHP : Get & Convert MONTH Input Type Value into STRING and Minus One Month From Input Value -


stackoverflow community. have unique experience. been google, trial , error hours still not find solution this. input , desired output pretty simple tricky, dont know how code properly.

well, define requirement.

explanation , requirement :

  1. i have input field. input field type month (not date). input field should produce year , month, different date input type produce complete date.

  2. i want echo value in month input field after converted string before (example : "2016-7" in string format) , produce "jul 2016".

this month format similar date format, script work date format, not working month format. thats make me wondering, im curious why.

experiment :

for basic input type month use script.

<input type="month" name="monthtransaction" value="<?php echo date("y-m") ?>"/> 

then tried echo it.

$month = mysql_real_escape_string($_post['monthtransaction']); $newmonth = date('y-m', strtotime(str_replace('-', '/', $tr))); echo $month; // string format (i need further explanation) echo $newmonth; // date format (i need further explanation) 

this not working after all. tried input field date type, working. echo fine date type format.

from code learn strtotime isn't convert date string. not know works (can echo) date format not month format.

if can tell me how convert month input type string, great, because can learn that.

desired output :

  1. it print in basic format "2016-07"
  2. it print in advanced format "july 2016"

=========================================================

second question (minus 1 month input value) :

well it's question related this.

second question explanation , requirement :

  1. i want input value in month input field minus 1 (-1) month input value.

second question desired output :

  1. so if enter "2016-07" example, give "2016-06" , on.

date format ordinary, month format seems challange me. know how fix ? said simple tricky. btw, thank in advance.

you can use datetime class

$month = mysql_real_escape_string($_post['monthtransaction']); $temp = new datetime($month.'-01'); $newmonth = $temp->format('y-m'); $newmonthname = $temp->format('f y'); $newmonthminusone = $temp->sub(new dateinterval('p1d'))->format('y-m'); $newmonthminusonename = $temp->sub(new dateinterval('p1d'))->format('f y'); 

with input '2016-07' values (all strings) be:

  • 2016-07
  • july 2016
  • 2016-06
  • june 2016

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -