Validate the datetime value: Difference between revisions
Jump to navigation
Jump to search
m
→MySQL approach
mNo edit summary |
m (→MySQL approach) |
||
| Line 3: | Line 3: | ||
== MySQL approach == | == MySQL approach == | ||
<pre> | <pre> | ||
SELECT `my_date_column`, | SELECT `my_date_column`, STR_TO_DATE(`my_date_column`, '%Y-%m-%d') | ||
FROM `my_table` | FROM `my_table` | ||
WHERE | WHERE | ||
STR_TO_DATE(`my_date_column`, '%Y-%m-%d') IS NULL; | |||
</pre> | </pre> | ||
| Line 12: | Line 12: | ||
Verify the value should be year/month/day format | Verify the value should be year/month/day format | ||
<pre> | <pre> | ||
SELECT `my_date_column`, | SELECT `my_date_column`, STR_TO_DATE(`my_date_column`, '%Y/%m/%d') | ||
FROM `my_table` | FROM `my_table` | ||
WHERE | WHERE | ||
STR_TO_DATE(`my_date_column`, '%Y/%m/%d') IS NULL; | |||
</pre> | </pre> | ||
| Line 21: | Line 21: | ||
Verify the value should be hour:minute:second format e.g. {{CURRENTTIME}}:06 | Verify the value should be hour:minute:second format e.g. {{CURRENTTIME}}:06 | ||
<pre> | <pre> | ||
SELECT `my_time_column`, | SELECT `my_time_column`, STR_TO_DATE(`my_time_column`, '%H:%i:%S') | ||
FROM `my_table` | FROM `my_table` | ||
WHERE | WHERE | ||
STR_TO_DATE(`my_time_column`, '%H:%i:%S') IS NULL; | |||
</pre> | </pre> | ||
| Line 30: | Line 30: | ||
Verify the value should be year-month-day hour:minute:second format e.g. {{Template:Today}} {{CURRENTTIME}}:06 | Verify the value should be year-month-day hour:minute:second format e.g. {{Template:Today}} {{CURRENTTIME}}:06 | ||
<pre> | <pre> | ||
SELECT `my_time_column`, | SELECT `my_time_column`, STR_TO_DATE(`my_time_column`, '%Y-%m-%d %H:%i:%S') | ||
FROM `my_table` | FROM `my_table` | ||
WHERE | WHERE | ||
STR_TO_DATE(`my_time_column`, '%Y-%m-%d %H:%i:%S') IS NULL; | |||
</pre> | </pre> | ||
== PHP appracoh == | |||
Using PHP [https://www.php.net/manual/en/function.strtotime.php strtotime] function | |||
== references == | == references == | ||