Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert AM/PM to 24-Hour Time In Big Query Standard SQL

How would I convert the following AM/PM value to the 24-hour clock time in Big Query standard SQL?

created_date 8/30/2018 2:23:38 PM

created_date 2018-08-30 14:23:38 UTC

like image 787
user9323006 Avatar asked Oct 30 '25 22:10

user9323006


1 Answers

First parse the timestamp string as a TIMESTAMP value, then format it in the desired way:

SELECT
  FORMAT_TIMESTAMP(
    '%Y-%m-%d %H:%M:%S %Z',
    PARSE_TIMESTAMP('%m/%d/%Y %I:%M:%S %p', created_date)
  ) AS created_date
FROM (
  SELECT '8/30/2018 2:23:38 PM' AS created_date
);
+-------------------------+
| created_date            |
+-------------------------+
| 2018-08-30 14:23:38 UTC |
+-------------------------+
like image 136
Elliott Brossard Avatar answered Nov 02 '25 13:11

Elliott Brossard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!