String to timestamp in MySQL(MySQL中时间戳的字符串)
问题描述
有没有办法在 MySQL 中将字符串转换为 UNIX 时间戳?
Is there any way to convert string to UNIX timestamp in MySQL?
例如,我的字符串 2011-12-21 02:20pm
需要采用 Unix 时间戳格式.
For example, I have the string 2011-12-21 02:20pm
which needs to be in Unix timestamp format.
推荐答案
UNIX_TIMESTAMP()
解决问题:
SELECT UNIX_TIMESTAMP('2011-12-21 14:20:00');
但是,UNIX_TIMESTAMP()
函数只采用标准 MySQL 格式的日期.如果要使用 AM/PM 表示法,则需要使用 STR_TO_DATE
首先像这样:
However, the UNIX_TIMESTAMP()
function only takes a standard MySQL formatted date. If you want to use the AM/PM notation, you will need to use STR_TO_DATE
first like this:
SELECT UNIX_TIMESTAMP(
STR_TO_DATE('2011-12-21 02:20pm', '%Y-%m-%d %h:%i%p')
);
这篇关于MySQL中时间戳的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL中时间戳的字符串


基础教程推荐
- 什么是 orradiag_<user>文件夹? 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01