简体   繁体   English

将 MySQL 日期时间 24 小时格式转换为 UNIX 时间戳

[英]Convert MySQL date time 24 hour format to UNIX timestamp

I'm storing date time in 04-09-2019 10:31:AM (4 September 2019 10:31 AM) in this format in MySQL table.我在 MySQL 表中以这种格式存储04-09-2019 10:31:AM (2019 年 9 月 4 日上午 10:31)的日期时间。

May I know how to convert this format to unixtime stamp in sql query我可以知道如何在 sql 查询中将此格式转换为unixtime

First you need to convert this into a proper mysql datetime using str_to_date() function.首先,您需要使用str_to_date()函数将其转换为正确的mysql日期str_to_date()

str_to_date(dd, '%d-%m-%Y %h:%i:%p')

Then after getting the correct datetime value, use unix_timestamp() function to convert it to unix timestamp.然后在获得正确的日期时间值后,使用unix_timestamp()函数将其转换为 unix 时间戳。

select 
    unix_timestamp(str_to_date(dd, '%d-%m-%Y %h:%i:%p'))
from test

try this dbfiddle .试试这个dbfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将带有日期和时间AM / PM的字符串转换为24小时的mysql时间戳格式 - How to convert string with date and time AM/PM to 24 Hour mysql timestamp format 将mySQL数据库的日志文件日期时间格式从12小时时钟批量转换为24小时时钟 - Bulk convert log file date time format from 12 hour clock to 24 hour clock for mySQL database 在 mysql 中转换为 24 小时格式 - convert to 24 hour format in mysql 使用php / Mysql中的选择查询将日期/时间从24小时格式转换为12小时AM / PM - convert date/time from 24-hour format to 12-hour AM/PM using select query in php/Mysql 将24小时格式转换为MySQL DATETIME格式 - Convert 24 hour format to MySQL DATETIME format 在mysql中将字符串转换为24小时日期时间格式 - convert string to 24 hour datetime format in mysql 在mysql中以2​​4小时格式获取日期范围 - Get a date range in 24 hour format in mysql MySQL SELECT按日期格式设置为24小时 - Mysql SELECT by date format as 24 hour 从 MySQL 中的 12 小时格式时间获取 24 小时格式时间/将 12 小时格式字符串读入时间,以便我可以将其转换为其他时间 - Get 24 hour format time from 12 hour format time in MySQL / Read 12 hour format string into time so I can convert it to another time MySQL默认current_timestamp不以24小时军事格式存储 - Mysql default current_timestamp not storing in 24 hour military format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM