当前位置:网站首页>From in MySQL_ Unixtime and UNIX_ Timestamp processing database timestamp conversion - Case
From in MySQL_ Unixtime and UNIX_ Timestamp processing database timestamp conversion - Case
2022-06-22 09:49:00 【JackieDYH】
MySQL Data sheet design in progress , Time fields are generally designed in timestamp format , It is a little inconvenient for developers to check . have access to FROM_UNIXTIME Convert to date format for viewing
If it is in date format , To convert to timestamp view , Only need to FROM_UNIXTIME Switch to UNIX_TIMESTAMP that will do
Case a
SELECT *,FROM_UNIXTIME(create_time) AS DATETIME FROM ebk_cls_io_log;
Case 2
select from_unixtime(at2.payTime, '%Y-%m-%d'), sum(at2.amount) from alipay_trade at2 group by from_unixtime(at2.payTime, '%Y-%m-%d'); 
Summary
1、 Time to time stamp
Get the current timestamp ( second )select unix_timestamp(); result :1599665897Get the date timestamp in the specified format
select unix_timestamp('2020-9-9'); result :1599580800Get the timestamp of the specified format date and timestamp
select unix_timestamp('2020-9-9 23:49:20'); result :15996665602、 Time stamp to time
grammar :FROM_UNIXTIME(unix_timestamp,format)
Time stamp (unix_timestamp) by 10 positionselect from_unixtime(1599666560,'%Y-%m-%d %H:%i:%S'); result :2020-09-09 23:49:20
| Format | describe | Example | Running results |
|---|---|---|---|
| %a | English abbreviation week name | SELECT FROM_UNIXTIME(1599666560,’%a’); | Tue |
| %b | English abbreviation month name | SELECT FROM_UNIXTIME( Now( ), ‘%b’ ) | Sep |
| %c | month , The number | SELECT FROM_UNIXTIME( Now( ), ‘%c’ ) | 9 |
| %D | The day of the month with English prefix | SELECT FROM_UNIXTIME( Now( ), ‘%D’ ) | 9th |
| %d | Day of the month , The number (00-31) | SELECT FROM_UNIXTIME( Now( ), '%d ’ ) | 09 |
| %e | Day of the month , The number (0-31) | SELECT FROM_UNIXTIME( Now( ), '%e ’ ) | 9 |
| %f | Microsecond | SELECT FROM_UNIXTIME(1599666560 , '%f ’ ) | 000000 |
| %H | Hours (00-23) | SELECT FROM_UNIXTIME(1599666560 , '%H ’ ) | 23 |
| %h | Hours (01-12) | SELECT FROM_UNIXTIME(1599666560 , '%h ’ ) | 11 |
| %I | Hours (01-12) | SELECT FROM_UNIXTIME(1599666560, ‘%I’ ) | 11 |
| %i | minute , The number (00-59) | SELECT FROM_UNIXTIME(1599666560, ‘%i’ ) | 49 |
| %j | Days of (001-366) | SELECT FROM_UNIXTIME(1599666560, ‘%j’ ) | 253 |
| %k | Hours (0-23) | SELECT FROM_UNIXTIME(1599666560, ‘%k’ ) | 23 |
| %l | Hours (1-12) | SELECT FROM_UNIXTIME(1599666560, ‘%l’ ) | 11 |
| %M | month , english | SELECT FROM_UNIXTIME(1599666560, ‘%M’ ) | September |
| %m | month , The number (00-12) | SELECT FROM_UNIXTIME(1599666560, ‘%m’ ) | 09 |
| %p | In the afternoon | SELECT FROM_UNIXTIME(1599666560, ‘%p’ ) | PM |
| %r | Time ,12- Hours (hh:mm:ss AM or PM) | SELECT FROM_UNIXTIME(1599666560, ‘%r’ ) | 11:49:20 PM |
| %S | second (00-59) | SELECT FROM_UNIXTIME(1599666560, ‘%S’ ) | 20 |
| %s | second (00-59) | SELECT FROM_UNIXTIME(1599666560, ‘%s’ ) | 20 |
| %T | Time , 24- Hours (hh:mm:ss) | SELECT FROM_UNIXTIME(1599666560, ‘%T’ ) | 23:49:20 |
| %U | Zhou (00-53) Sunday is the first day of the week | SELECT FROM_UNIXTIME(1599666560, ‘%U’ ) | 36 |
| %u | Zhou (00-53) Monday is the first day of the week | SELECT FROM_UNIXTIME(1599666560, ‘%u’ ) | 37 |
| %V | Zhou (01-53) Sunday is the first day of the week , And %X Use | SELECT FROM_UNIXTIME(1599666560, ‘%V’ ) | 36 |
| %v | Zhou (01-53) Monday is the first day of the week , And %x Use | SELECT FROM_UNIXTIME(1599666560, ‘%v’ ) | 37 |
| %W | What day of the week , English full name | SELECT FROM_UNIXTIME(1599666560, ‘%W’ ) | Wednesday |
| %w | Days of the week (0= Sunday , 6= Saturday ) | SELECT FROM_UNIXTIME(1599666560, ‘%w’ ) | 3 |
| %X | year ,4 position , Sunday is the first day of the week , And %V Use | SELECT FROM_UNIXTIME(1599666560, ‘%X’ ) | 2020 |
| %x | year ,4 position , Monday is the first day of the week , And %v Use | SELECT FROM_UNIXTIME(1599666560, ‘%x’ ) | 2020 |
| %Y | year ,4 position | SELECT FROM_UNIXTIME(1599666560, ‘%Y’ ) | 2020 |
| %y | year ,2 position | SELECT FROM_UNIXTIME(1599666560, ‘%y’ ) | 20 |
边栏推荐
- Solend废止「接管巨鲸」提案 清算「炸弹」未除
- Advanced Web Zone record of attack and defense world (I)
- Recruitment order | data visualization development platform "flyfish" super experience Officer Recruitment
- [node] please accept the crawler. We won't worry about the data any more
- 如何将数据库中的值经过Servlet传到jsp页面通过EL表达式中显示出来?
- Software engineering topics
- 前 AMD 芯片架构师吐槽,取消 K12 处理器项目是因为 AMD 怂了!
- 7-1 group minimum
- Learning serialization and deserialization from unserialize3
- Langchao state-owned assets cloud: state-owned assets as a guide to help state-owned enterprises use data to enrich their wisdom in the cloud
猜你喜欢

Basic knowledge of AI Internet of things | community essay solicitation

信息系统项目典型生命周期模型

软件工程 大题

Double machine hot standby of firewall on ENSP

架设多个web站点

Ctfshow Web Learning Records

Shengdun technology joined dragon lizard community to build a new open source ecosystem

Qt编写物联网管理平台36-通信协议

Kali uses the command ifconfig to query the solution that the IP address is always 127.0.0.1

FileZilla server prompts 550 could not open file for reading when downloading files (illustration)
随机推荐
How to transfer the values in the database to JSP pages through servlets and display them in El expressions?
Hoo Research Institute of Hufu: how does cosmos connect the chain with the "port" of the chain?
双指针仪表盘读数(二) ——表盘位置识别
一句话木马上传常见的几种方法
day500:键盘行
day575: 分糖果
6-7 average the surrounding elements of a two-dimensional array
day260:只出现一次的数字 III
论文笔记:DETR: End-to-End Object Detection with Transformers (from 李沐老师and朱老师)
呼叫中心专业术语
SQL编程task02作业-基础查询与排序
[node] please accept the crawler. We won't worry about the data any more
如何将数据库中的值经过Servlet传到jsp页面通过EL表达式中显示出来?
一口气读懂 IT发展史
SQL编程task06作业-秋招秘籍ABC
AttributeError: module ‘skimage.draw‘ has no attribute ‘circle‘
When golang operates mongodb, vscode prompts primitive E composite literal uses unlocked fields
[模板] kmp
快速掌握 ASP.NET 身份认证框架 Identity - 登录与登出
[cmake命令笔记]target_compile_options