Wednesday, November 13, 2013

MySQL NOW() function add 1 hour, day, month, year



MySQl NOW() function returns current time with format ‘YYYY-MM-DD HH:MM:SS’. If we use
NOW()+1, a second is added, but the return value format is changed to:
YYYYMMDDHHMMSS.uuuuuu #sthash.K5ILIJDY.dpuf
 
 YYYYMMDDHHMMSS.uuuuuu
MySQL statement example 1:
 SELECT NOW(), NOW() + 1;
we will get
 '2013-11-13 13:17:07', 20131113131708.000000
To keep the same format: we can use
NOW() + INTERVAL 1 second;
to add a second with format ‘YYYY-MM-DD HH:MM:SS’

MySQL statement example 2:
 SELECT NOW(), NOW() + INTERVAL 1 second;
 we will get
 '2013-11-13 13:19:21', '2013-11-13 13:19:22'
Similarly  we can add 1 hour, 1 day, 1 month or one year using
+INTERVAL 1 hour,  +INTERVAL 1 month, +INTERVAL 1 year

We can use "-" to reduce time.


YYYYMMDDHHMMSS
YYYYMMDDHHMMSS.uuuuuu #sthash.K5ILIJDY.dpuf
YYYYMMDDHHMMSS.uuuuuu #sthash.K5ILIJDY.dpuf
YYYYMMDDHHMMSS.uuuuuu #sthash.K5ILIJDY.dpuf

No comments:

Post a Comment