[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

c# dates manipulations in c#

Posted on 2007-07-26
4
Medium Priority
?
217 Views
Last Modified: 2010-04-15
what are the functions that allow to do dates manipulations. for example, i need a date in a format YYYY-MM-DD and i need to get a difference between days and convert it to years.
0
Comment
Question by:jgordin
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 19574344
you can use the ToString like this for example

DateTime d1 = new DateTime(190,01,01);
d1.ToString("YYYY-MM-DD");

Then for difference you have a TimeSpan

so TimeSpan t1 = DateTime.Now.AddYears(10) - DateTime.Now;
t1.TotalDays
etc....

Andrew
0
 
LVL 8

Accepted Solution

by:
sabeesh earned 2000 total points
ID: 19574352
DateTime date = DateTime.Now;
            string str = date.ToString("yyyy-MM-dd");
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 19574363
BTW typo

DateTime d1 = new DateTime(190,01,01);

I mean to write

DateTime d1 = new DateTime(1900,01,01);

:-o

Andrew
0
 
LVL 8

Expert Comment

by:sabeesh
ID: 19574389
Date diff

 DateTime date = DateTime.Now;
            DateTime dte2 = new DateTime(2007,12,23);
            TimeSpan span = dte2 - date;
            int days = span.Days;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question