Innova
Innova

Reputation: 4981

i have a date (eg: 2010-04-17 ) i need the date of after 20 days from this date

i have a date (eg: 2010-04-17 ) i need the date of after 20 days from this date How to get the date after 20 days i.e next month some date.

either in sql or in c#

Upvotes: 0

Views: 312

Answers (5)

Oracle:

SELECT DATE_COLUMN + INTERVAL '20' DAY FROM MY_TABLE;

or

SELECT DATE_COLUMN + 20 FROM MY_TABLE;

PL/SQL:

BEGIN
  dtMy_date  DATE;

  SELECT DATE_COLUMN INTO dtMy_date FROM MY_TABLE;

  dtMy_date := dtMy_date + INTERVAL '20' DAY;
  -- or
  dtMy_date := dtMy_date + 20;
END;

Share and enjoy.

Upvotes: 0

Jamie Ide
Jamie Ide

Reputation: 49291

If the date is already a DateTime object, then you can call

var nextDate = myDate.AddDays(20);

If it's a string then you will need to firt convert it to a DateTime:

var myDate = DateTime.Parse("2010-04-17");
var nextDate = myDate.AddDays(20);

Note that the AddDays method returns a new DateTime, it doesn't add days to the original DateTime.

Upvotes: 2

Alex K.
Alex K.

Reputation: 175876

T-SQL: DATEADD(DAY, 20, thedate)

C#: DateTime.Add()

Upvotes: 1

Guffa
Guffa

Reputation: 700592

In C# you use the AddDays method:

DateTime someDate = new DateTime(2010, 4, 17);
DateTime later = someDate.AddDays(20);

In SQL you would use some date manipulation function, which is specific to the different dialects of SQL. In MS SQL Server for example you would use the dateadd function:

dateadd(day, 20, someDate)

Upvotes: 4

PatrickJ
PatrickJ

Reputation: 1093

This is quite simple in C#

            DateTime date = new DateTime(2010, 04, 17);
            DateTime newDate = date.AddDays(20);

You can construct the original date variable in whatever way is easiest to you, then use the AddDays method to create a new variable (or update the existing one) with the date any number of days afterwards.

Upvotes: 10

Related Questions