How to Add Days to Date

How can I add 1 day to current date?

To add one day to a date object:

var date = new Date();

// add a day
date.setDate(date.getDate() + 1);

add day to date javascript

Try this

var date1 = new Date("03/31/2016");

var next_date = new Date(date1.getTime() + 86400000);

alert(next_date.toLocaleDateString());

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)

How to add days to a date and pass the sum to an inputdate in c #?

The following code snippet contains two InputDate components. When you select a date in the first one, the date in the second one changed to the selected date in the first component plus 45 days.

    @page "/"

<EditForm EditContext="EditContext" OnValidSubmit="HandleValidSubmit">
<DataAnnotationsValidator />

<InputDate placeholder="Arrival Date" @bind-Value="person.ArrivalDate"
@oninput="AddDays" />
<InputDate placeholder="Departure Date" @bind-Value="person.DepartureDate" />
<ValidationMessage For="@(() => person.ArrivalDate)" />
<ValidationMessage For="@(() => person.DepartureDate)" />

<p><button type="submit">Submit</button></p>
</EditForm>

@code {

private Person person = new Person();
EditContext EditContext;

protected override void OnInitialized()
{
EditContext = new EditContext(person);
base.OnInitialized();
}

private async Task AddDays(ChangeEventArgs args)
{
person.DepartureDate = Convert.ToDateTime(args.Value).AddDays(45);
await Task.CompletedTask;
}

void HandleValidSubmit()
{
Console.WriteLine("TODO: Actually do something with the valid data");
}

public class Person
{
public DateTime ArrivalDate { get; set; } = DateTime.Now;
public DateTime DepartureDate { get; set; } = DateTime.Now;

}
}

Hope this helps...

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);


Related Topics



Leave a reply



Submit