将SQL/PHP中的日期输入格式从Y/M/D更改为D/M/Y

时间:2022-05-23 21:31:28

I need to be able to change the date format from Y/M/D to D/M/Y. The database with all the data that I am querying has the date set as Y/M/D whereas the input form has the input yet as D/M/Y.

我需要能够将日期格式从Y/M/D更改为D/M/Y。我查询的所有数据的数据库的日期设置为Y/M/D,而输入表单的输入仍然是D/M/Y。

Does anyone have any idea how I can change the format?

有人知道我怎样才能改变格式吗?

NB the Date is 'DOB'

日期是DOB

Here is the SQL:

这是SQL:

$sql="SELECT `country_name`,`gdp`,`population`,Cyclist.name,Cyclist.dob FROM Country JOIN Cyclist ON Country.ISO_id=Cyclist.ISO_id 
WHERE 'dob'
BETWEEN '".$date_1."' AND '".$date_2."'";

Here is the PHP for getting the data from the form submission

下面是从表单提交中获取数据的PHP

$date_1=$_REQUEST['date_1'];
$date_2=$_REQUEST['date_2'];

2 个解决方案

#1


2  

STR_TO_DATE parses a string to a date use a given format.

STR_TO_DATE使用给定的格式将字符串解析为日期。

$sql="SELECT `country_name`,`gdp`,`population`,Cyclist.name,Cyclist.dob FROM Country JOIN Cyclist ON Country.ISO_id=Cyclist.ISO_id 
WHERE 'dob'
BETWEEN STR_TO_DATE('".$date_1.",'%d,%m,%Y') AND STR_TO_DATE('".$date_2.",'%d,%m,%Y')'";

STR_TO_DATE: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

STR_TO_DATE:https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html # function_str-to-date

#2


0  

You may change the date format in php date() and strtotime() e.g: $date_new = date('d-m-Y', strtotime($date)); and then passing it in sql query.

您可以在php date()和strtotime() e中更改日期格式。g: $date_new = date('d-m-Y', strtotime($date));然后在sql查询中传递它。

#1


2  

STR_TO_DATE parses a string to a date use a given format.

STR_TO_DATE使用给定的格式将字符串解析为日期。

$sql="SELECT `country_name`,`gdp`,`population`,Cyclist.name,Cyclist.dob FROM Country JOIN Cyclist ON Country.ISO_id=Cyclist.ISO_id 
WHERE 'dob'
BETWEEN STR_TO_DATE('".$date_1.",'%d,%m,%Y') AND STR_TO_DATE('".$date_2.",'%d,%m,%Y')'";

STR_TO_DATE: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

STR_TO_DATE:https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html # function_str-to-date

#2


0  

You may change the date format in php date() and strtotime() e.g: $date_new = date('d-m-Y', strtotime($date)); and then passing it in sql query.

您可以在php date()和strtotime() e中更改日期格式。g: $date_new = date('d-m-Y', strtotime($date));然后在sql查询中传递它。