Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get tomorrows date

Tags:

sql

sql-server

I am trying to get tomorrows date in a sql statement for a date comparison but it is not working.

Below is my code:

select *  from tblcalendarentries where convert(varchar,tblcalendarentries.[Start Time],101)        = convert(varchar, GETDATE() +1, 101) 
like image 792
user1292656 Avatar asked Apr 16 '13 09:04

user1292656


People also ask

How can I get tomorrow date?

1const todayMoment = moment() //returns the current date with moment instance. To get tomorrow date, you just need to add +1 days to the today moment instance. Here, we clone the todayMoment instance. because moment instance are mutable.

How can I get tomorrow date in node JS?

You just have to get the current date and you can use the setDate method on the Date object to set the day of the date. Then you can increase the date by the number of days you need. In this example, to get tomorrow's date, we can increase it by 1.

What is tomorrow's date mean?

n. 1 the day after today. 2 the future.


1 Answers

To get tomorrows date you can use the below code that will add 1 day to the current system date:

SELECT DATEADD(day, 1, GETDATE()) 

GETDATE()

Returns the current database system timestamp as a datetime value without the database time zone offset. This value is derived from the operating system of the computer on which the instance of SQL Server is running.

DATEADD(datepart , number , date)

Returns a specified date with the specified number interval (signed integer) added to a specified datepart of that date.

So adding this to your code in the WHERE clause:

WHERE CONVERT(VARCHAR, tblcalendarentries.[Start Time], 101) =        CONVERT(VARCHAR, DATEADD(DAY, 1, GETDATE()), 101); 

First off, GETDATE() will get you today's date in the following format:

2013-04-16 10:10:02.047 

Then using DATEADD(), allows you to add (or subtract if required) a date or time interval from a specified date. So the interval could be: year, month, day, hour, minute etc.

Working with Timezones?

If you are working with systems that cross timezones, you may also want to consider using GETUTCDATE():

GETUTCDATE()

Returns the current database system timestamp as a datetime value. The database time zone offset is not included. This value represents the current UTC time (Coordinated Universal Time). This value is derived from the operating system of the computer on which the instance of SQL Server is running.

like image 75
Tanner Avatar answered Oct 11 '22 20:10

Tanner