MySQL时间函数-获取当前时间-时间差

MySQL中获取当前时间为now(),不同于sqlserver getdate()。

SQLServer转MySQL除变化top 1 -> limit 1之后报错:

select  1 from record_visitor where visitor_ip=‘‘ and datediff(mi,visitor_time,getdate())<=30 limit 1

[Err] 1582 - Incorrect parameter count in the call to native function ‘datediff‘

搜索了是MySQL->DATEDIFF只计算到天的单位。

正确写法:

select  1 from record_visitor where visitor_ip=‘‘ and TIMESTAMPDIFF(MINUTE,visitor_time,now())<=30 limit 1
时间: 2024-08-08 13:52:58

MySQL时间函数-获取当前时间-时间差的相关文章

MySQL字符串函数、日期时间函数

MySQL字符串函数.日期时间函数 一.常见字符串函数: 1.CHAR_LENGTH  获取长度(字符为单位) 2.FORMAT  格式化 3.INSERT  替换的方式插入 4.INSTR  获取位置 5.LEFT/RIGHT  取左.取右 6.LENGTH   获取长度(字节为单位) 7.LTRIM/RTRIM/TRIM 去空格(左/右/自定义) 8.STRCMP  字符串比较 9.CONCAT  字符串拼接 10.SUBSTRING  字符串截取 1.CHAR_LENGTH:获取长度(字符

MySQL数据库学习笔记(五)----MySQL字符串函数、日期时间函数

一.常见字符串函数: 1.CHAR_LENGTH  获取长度(字符为单位) 2.FORMAT  格式化 3.INSERT  替换的方式插入 4.INSTR  获取位置 5.LEFT/RIGHT  取左.取右 6.LENGTH   获取长度(字节为单位) 7.LTRIM/RTRIM/TRIM 去空格(左/右/自定义) 8.STRCMP  字符串比较 9.CONCAT  字符串拼接 10.SUBSTRING  字符串截取 1.CHAR_LENGTH:获取长度(字符为单位) CHAR_LENGTH(s

MySQL sql语句获取当前日期|时间|时间戳

1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +-------+ | now() | +-------+ | 2013-04-08 20:56:19 | +-------+ 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: current_timestamp() ,current_timestamp ,localtime() ,localtime ,localtimestamp - (v4.0.6) ,

从erlang时间函数说到时间校正体系

很多人会注意到这个问题,erlang提供了2个时间函数,erlang:now() 和 os:timestamp().用法一样,都是返回当前的时间.具体时间是从1970年1月1日零时算起,到现在经过的时间,结果为{MegaSecs, Secs, MicroSecs}. 这两个函数有什么区别? os:timestamp() 获取到的时间为操作系统的时间,不做任何修正:而erlang:now(),每次获取都会确保生成了唯一的时间,就是说,erlang:now()在实现上对时间做了一个校正,每次都生成一

Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数

格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: 1 /** 2 * 获取指定时间到格林威治时间的秒数 3 * UTC:格林威治时间1970年01月01日00时00分00秒(UTC+8北京时间1970年01月01日08时00分00秒) 4 * @param time 5 * @return 6 */ 7 public static long diffSeconds(String time){

js 的date的format时间,获取当前时间,前一天的日期

Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds()

redis基本操作,基于StringRedisTemplate,存储,取值,设置超时时间,获取超时时间,插入list操作

@Autowired private StringRedisTemplate stringRedisTemplate; @GetMapping("/test") void test() { stringRedisTemplate.opsForValue().set("liuqi", "13221050705", 15, TimeUnit.MINUTES); String str1 = stringRedisTemplate.opsForValue

MySQL max函数获取最大值错误

问题描述 通过sql查询得到的最大值为947669 但是通过查看表数据的最大值为1120184 这是因为registered_Live_User字段的数据类型为varchar类型. 所以max获取的最大值会从头开始比较,947669的第一位为9,1120184的第一位为1,所以max函数获取的最大值为9开头的数值. 解决办法 如果在不修改数据库表结构的情况下. 可以在max函数里面+0解决. 这样获取的值才是最大值 原文地址:https://www.cnblogs.com/oyjg/p/1256

nodejs 模块moment格式化时间,获取当前时间的前一天时间

var moment = require('moment'); moment.locale('zh-cn'); var today = {}; var _today = moment(); today.year = _today.format('yyyy'); /*现在的年*/ today.date = _today.format('YYYY-MM-DD'); /*现在的时间*/ today.yesterday = _today.subtract(1, 'days').format('YYYY-