Loading

Adding minutes to a datetime variables

Submitted by: 


Sometime we stuck in a problem in which we have to get a time which is after 20 or 60 minutes then there is simple function which can add minutes to a particular datetime variable
take an example we want to add 60 minutes to present time, for this we simply do is make an 2 objects of current datetime class i.e. date1 and date2

  1.  
  2. System.DateTime date1 = System.DateTime.Now;
  3. System.DateTime date2 = System.DateTime.Now;

after that simply add 60 minutes to the second datetime object created earlier with the help of AddMinutes method like below

  1.  
  2. System.DateTime date2new = date2.AddMinutes(60);
  1.  
  2. Method * Description
  3. Add Adds a timespan value
  4. AddDays Adds a certain number of days
  5. AddHours Adds a certain number of hours
  6. AddMilliseconds Adds a certain number of Milliseconds
  7. AddMinutes Adds a certain number of minutes
  8. AddMonths Adds a certain number of months
  9. AddSeconds Adds a certain number of seconds
  10. AddTicks Adds a certain number of ticks
  11. AddYears Adds a certain number of years
  12. GetDateTimeFormats Returns a list of available datetime formats
  13. GetHashCode Returns hashcode for a certain date. int is returned
  14. IsDaylightSavingTime Determines if a datetime object is daylightsavings
  15. Subtract Subtracts a timespan object from datetime object
  16. ToBinary Serializes object to long value to be used later
  17. ToFileTime Converts datetime to a windows file time
  18. ToLocalTime Returns a local time object as datetime
  19. ToLongDateString Returns a string as a longdate format
  20. ToLongTimeString Returns a string as a long time format
  21. ToOADate Converts a datetime object to a OLE automation date
  22. ToShortDateString Returns a short date format
  23. ToShortTimeString Returns a short time format
  24. ToString Returns a string that represents the datetime object

* http://www.meshplex.org/wiki/C_Sharp/Da ... nd_Objects

About the author:

PlanetSourceCode.in is a place for all developer providing free source codes, articles, MCA complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development




Comments

post is very useful one for me

Wow! That's a really neat asnewr!

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.