×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

How to add minutes in the current date time in C#?

C# | DateTime.AddMinutes() Method Example: Here, we are going to learn how we can add the minutes in the current date and time in C#? Submitted by IncludeHelp, on October 18, 2019

To add minutes in the current date-time, we use AddMinutes() method of DateTime class in C#.

Syntax

DateTime DateTime.AddMinutes(double);

AddMinutes() method accepts the value of the minutes as double and returns the DateTime object that can be parsed and updated date time can be found.

C# code to add minutes in current date time

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an object of DateTime class
            //and, initializing it with the current time 
            //using "Now"           
            DateTime dt1 = DateTime.Now;

            //printing current date time
            Console.WriteLine("Currnt date time is: " + dt1.ToString());
            
            //another DateTime object to store the updated date time
            //adding 15 minutes
            DateTime dt2 = dt1.AddMinutes(15);
            //updated date time is 
            Console.WriteLine("Updated date time is: " + dt2.ToString());

            //adding 2880 minutes (i.e. 2 days) in the time 
            dt2 = dt1.AddMinutes(2880);
            //updated date time is 
            Console.WriteLine("Updated date time is: " + dt2.ToString());

            //just to print a new line
            Console.WriteLine();
        }
    }
}

Output

RUN 1:
Currnt date time is: 10/17/2019 5:05:43 PM
Updated date time is: 10/17/2019 5:20:43 PM
Updated date time is: 10/19/2019 5:05:43 PM

RUN 2:
Currnt date time is: 10/17/2019 5:06:19 PM
Updated date time is: 10/17/2019 5:21:19 PM
Updated date time is: 10/19/2019 5:06:19 PM
Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.