如何显示已以月份,年份格式保存在sql中的html month tag输入?

我已经使用html输入月份标签来按照客户端的要求输入日历,它以文本形式保存在sqldatabase表中,其格式为2019-03,而我需要的格式为2019年3月。

我用过date_format(),date(),strtotime(),但是它没有用,因为输入标记不是完全采用日期格式...而且我也在stackoverflow上搜索了答案,但找不到任何答案。

接受用户输入时

<input name= 'apmtr' type= 'month' id='datePicker' value='<?php set_value('apmtr');?>' class='form-control required'>

向用户显示时

<?php echo $dsr[0]['apmtr'];?>

当仅使用php从数据库中获取价值时,我需要在2019年3月使用它。


杨__羊羊
浏览 184回答 3
3回答

阿晨1998

这可以为您提供所需的输出。<?php&nbsp;print date('F-Y', strtotime($string)); // $string would be database column name?>&nbsp;

白猪掌柜的

您可以直接在mysql中使用&nbsp;select&nbsp; date_format(str_to_date('2019-03', '%Y-%m'), '%M-%Y')&nbsp;select&nbsp; date_format(str_to_date(your_col_string, '%Y-%m'), '%M-%Y') apmtr&nbsp;from your_table&nbsp;

胡子哥哥

您可以直接这样做echo&nbsp;date("F-Y",&nbsp;strtotime("2019-03"));您将从此链接获得所需的所有格式。输出March-2019演示版
打开App,查看更多内容
随时随地看视频慕课网APP