Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need to program and get the following dates


1. 1 Sep 2014


2 1 Jan 2014


please assist with codes.
Posted
Comments
Samatha Reddy G 18-Sep-14 6:36am    
i am not getting you exactly..

you need to return the date format like "1 Sep 2014"....
Member 10744248 18-Sep-14 8:40am    
For any month the system should generate the first day (1), combine it with the month and year

For instance the current date is 18 Sep 2014

expected ouput 1 Sep 2014'

Hi,

Have a look at the DateTime Constructor.
This will show you how to create DateTime objects in C#.

You can use it like this:
C#
DateTime dtFirstDate = new DateTime(2014, 9, 1);
DateTime dtSecondDate = new DateTime(2014, 1, 1);


Hope it helps.
 
Share this answer
 
Comments
Member 10744248 18-Sep-14 8:11am    
DateTime dt1 = DateTime.Now;

txtFromDate.Text=(Year.dt1,Month.dt1,1)
hypermellow 18-Sep-14 8:17am    
Hi,

Something like this:

DateTime dt1 = DateTime.Now;
txtFromDate.Text=new DateTime(dt1.Year,dt1.Month,1).ToShortDateString();
Try:
C#
DateTime dt1;
if (!DateTime.TryParse("1 Sep 2014", out dt1))
    {
    // Report error to whatever
    return;
    }
DateTime dt2;
if (!DateTime.TryParse("1 Jan 2014", out dt2))
    {
    // Report error to whatever
    return;
    }
TimeSpan diff = dt1 - dt2;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900