Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add days to a date column along with time in SQL

I want to add 1 day to read_date column along with time.

below is the sample column data

read_date
-----------------------
01-01-19 01:00:00.000000000 AM


Expected Result
---------------------
02-01-19 01:00:00.000000000 AM

I have tried below but it is adding only day not time.

select read_time, read_time+1
from meter_read_alert

read_date                           read_date+1
------------------------------------------------------
01-01-19 12:00:00.000000000 AM      02-01-19
01-01-19 01:00:00.000000000 AM      02-01-19
like image 959
Puja Shaw Avatar asked Oct 30 '25 22:10

Puja Shaw


1 Answers

When you use + 1, the timestamp is converted to a date. That is why you are only seeing the date (the default representation of a date does not include the time component although it is there).

Instead, use interval:

select read_time, read_time + interval '1' day
from meter_read_alert;

PS. I learned something from this. Interesting question.

like image 120
Gordon Linoff Avatar answered Nov 01 '25 12:11

Gordon Linoff