Add Number of Days to a Date

Adding days to a date in Python

The previous answers are correct but it's generally a better practice to do:

import datetime

Then you'll have, using datetime.timedelta:

date_1 = datetime.datetime.strptime(start_date, "%m/%d/%y")

end_date = date_1 + datetime.timedelta(days=10)

python: adding any number of days to date

x=20100103
x2 = int((datetime.datetime.strptime(str(x),"%Y%m%d") + datetime.timedelta(days=10)).strftime("%Y%m%d"))

to break it down

x=20100103
x_as_datetime = datetime.datetime.strptime(str(x),"%Y%m%d")
new_datetime = x_as_datetime + datetime.timedelta(days=10) #add your timedelta
x2 = new_datetime.strftime("%Y%m%d") # format it back how you want
int(x2) # if you just want an integer ...

Add number of days to a date

This should be

echo date('Y-m-d', strtotime("+30 days"));

strtotime

expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

while date

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

See the manual pages for

  • http://www.php.net/manual/en/function.strtotime.php
  • http://www.php.net/manual/en/function.date.php

and their function signatures.

How to add number of days to exact date format

Use this code:

$today = date("m/d/y");
echo date('m/d/y', strtotime($today. ' +10 day'));

Out put will be 11/28/13 as you desiring.

Add number of days to date android

You need to parse the string to a date first.

     SimpleDateFormat dateParser = new SimpleDateFormat("MM/dd/yyyy");
try {
Date myDate = dateParser.parse("01/01/2015");
Calendar c = Calendar.getInstance();
c.setTime(myDate);
c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + 20);
Date newDate = c.getTime();
String newFormattedDate = dateParser.format(newDate);//01/21/2015
} catch (ParseException e) {
e.printStackTrace();
//handle exception

}

How to add one day to a date?

Given a Date dt you have several possibilities:

Solution 1: You can use the Calendar class for that:

Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE, 1);
dt = c.getTime();

Solution 2: You should seriously consider using the Joda-Time library, because of the various shortcomings of the Date class. With Joda-Time you can do the following:

Date dt = new Date();
DateTime dtOrg = new DateTime(dt);
DateTime dtPlusOne = dtOrg.plusDays(1);

Solution 3: With Java 8 you can also use the new JSR 310 API (which is inspired by Joda-Time):

Date dt = new Date();
LocalDateTime.from(dt.toInstant()).plusDays(1);

Adding number of days to a date in SQL?

'2020-08-31' is a varchar(10), days(middle_date) casts it to a date because days() wants a date, but middle_date+days_to_add tries to cast it to a DECFLOAT, and fails.

Add date keyword before value

SELECT  ACCOUNT_NUMBER, FIRST_TRANSACTION_DATE, MIDDLE_DATE, MIDDLE_DATE+DAYS_TO_ADD AS END_DATE
FROM
(--SUBQUERY 1
SELECT ACCOUNT_NUMBER, FIRST_TRANSACTION_DATE, MIDDLE_DATE, DAYS(MIDDLE_DATE)-DAYS(FIRST_TRANSACTION_DATE) AS DAYS_TO_ADD
FROM
(--SUBQUERY 2
SELECT ACCOUNT_NUMBER, FIRST_TRANSACTION_DATE, date '2020-08-31' AS MIDDLE_DATE
FROM TABLE1
)
)
;

Trying to add number of days to date but format is wrong

Try the below code with mm/dd/yyyy date format

var date = '12/07/2016';
var ValidToDate = new Date(date);
var numberOfDaysToAdd = 30;
ValidToDate.setDate(ValidToDate.getDate() + numberOfDaysToAdd);
document.write(ValidToDate.getDate()+'/'+(ValidToDate.getMonth()+1)+'/'+ValidToDate.getFullYear());

Update with dd/mm/yyyy date format