PHP and MySQL syntax: Difference between revisions
m →Debug Tag: wikieditor |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 101: | Line 101: | ||
{{exclaim}} Since {{kbd | key=<nowiki>echo $(date '+%N')</nowiki>}} was not supported on {{Mac}}<ref>[https://superuser.com/questions/599072/how-to-get-bash-execution-time-in-milliseconds-under-mac-os-x macos - How to get Bash execution time in milliseconds under Mac OS X? - Super User]</ref>, alternative approach is the installation of {{kbd | key=gdate}}. | {{exclaim}} Since {{kbd | key=<nowiki>echo $(date '+%N')</nowiki>}} was not supported on {{Mac}}<ref>[https://superuser.com/questions/599072/how-to-get-bash-execution-time-in-milliseconds-under-mac-os-x macos - How to get Bash execution time in milliseconds under Mac OS X? - Super User]</ref>, alternative approach is the installation of {{kbd | key=gdate}}. | ||
=== | === Specified time === | ||
==== Convert the unix timestamp to '''human readable''' time format ==== | ==== Convert the unix timestamp to '''human readable''' time format ==== | ||
ex: 2010-12-21 10:05:06 | ex: 2010-12-21 10:05:06 | ||
| Line 150: | Line 150: | ||
* Excel | * Excel | ||
==== Convert | ==== Convert the datetime to ISO foamt time format ==== | ||
[[Convert date time from | Using the [https://www.php.net/manual/en/datetime.createfromformat.php DateTime::createFromFormat]<ref>[https://stackoverflow.com/questions/10306999/php-convert-date-format-dd-mm-yyyy-yyyy-mm-dd PHP convert date format dd/mm/yyyy => yyyy-mm-dd - Stack Overflow]</ref> | ||
<pre> | |||
$date = DateTime::createFromFormat('d/m/Y', "29/03/2021"); | |||
echo $date->format('Y-m-d'); | |||
// output: 2021-03-29 | |||
$date = DateTime::createFromFormat('M d D Y H:i', "Jun 04 Sun 2023 08:25"); | |||
echo $date->format('Y-m-d H:i:s'); | |||
// output: 2023-06-04 08:25:00 | |||
</pre> | |||
The following instruction written by ChatGPT | |||
<pre> | |||
// The input datetime string | |||
$input = "Jun 04 Sun 2023 08:25"; | |||
// Specify the input format | |||
$inputFormat = "M d D Y H:i"; | |||
// Create a DateTime object from the input string | |||
$dateTime = DateTime::createFromFormat($inputFormat, $input); | |||
// Check if the DateTime object was created successfully | |||
if ($dateTime === false) { | |||
echo "Failed to parse the input datetime string."; | |||
} else { | |||
// Format the DateTime object into the desired ISO format | |||
$isoFormat = "Y-m-d H:i:s"; | |||
$output = $dateTime->format($isoFormat); | |||
// Print the output | |||
echo $output; // "2023-06-04 08:25:00" | |||
} | |||
</pre> | |||
==== Convert date time from Zulu format ==== | |||
[[Convert date time from zulu format]] e.g. {{Template:Today}}T10:59:39.000Z | |||
==== Previous month based on current month ==== | ==== Previous month based on current month ==== | ||
| Line 394: | Line 431: | ||
# (optional) Adjust the text size to 10 | # (optional) Adjust the text size to 10 | ||
== | == Debug == | ||
[[SQL syntax debug]] | PHP | ||
* [https://www.php.net/manual/en/function.debug-backtrace.php PHP: debug_backtrace - Manual] | |||
MySQL | |||
* [[SQL syntax debug]] | |||
== References == | == References == | ||