xtd 0.2.0
Loading...
Searching...
No Matches

◆ add_days()

date_time xtd::date_time::add_days ( double  value) const

Returns a new xtd::date_time that adds the specified number of days to the value of this instance.

Parameters
valueA number of whole and fractional days. The value parameter can be negative or positive.
Returns
An object whose value is the sum of the date and time represented by this instance and the number of days represented by value.
Exceptions
xtd::argument_out_of_range_exceptionThe resulting xtd::date_time is less than xtd::date_time::min_value or greater than xtd::date_time::max_value.
Examples
The following example uses the xtd::date_time::add_days method to determine the day of the week 36 days after the current date.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
class program {
public:
static auto main() {
// Calculate what day of the week is 36 days from this instant.
auto today = xtd::date_time::now();
auto answer = today.add_days(36);
xtd::console::write_line("{0}", today);
xtd::console::write_line("{0}", answer);
}
};
startup_(program::main);
// This code can produce the following output :
//
// Wed Jan 12 14:06:34 2022
// Thu Feb 17 14:06:34 2022
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static date_time now() noexcept
Gets a xtd::date_time object that is set to the current date and time on this computer,...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
Remarks
This method does not change the value of this xtd::date_time. Instead, it returns a new xtd::date_time whose value is the result of this operation.
The fractional part of value is the fractional part of a day. For example, 4.5 is equivalent to 4 days, 12 hours, 0 minutes, 0 seconds, 0 milliseconds, and 0 ticks.
The xtd::date_time::add_days method takes into account leap years and the number of days in a month when performing date arithmetic.