Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.21/5 (4 votes)
See more:
              Console.WriteLine("please enter start date");
          List <int>  start = new List  <int>();

               for (int i = 0; i <= 4; i++)
               {
                       start.Add(i);
                    Console.ReadLine();      }


   List <int>  end = new List  <int>();

               for (int i = 0; i <= 4; i++)
               {
                       end.Add(i);
                    Console.ReadLine();      }

// how to do that  in the run time start result was "01.01.1990 " ,"01.01.1999" and end result was  "02.01.1990","09.10.2013"
Posted
Updated 8-Nov-13 1:13am
v5
Comments
Thanks7872 8-Nov-13 6:43am    
What?
Thomas ktg 8-Nov-13 6:46am    
There is no proper information in your question. Please use Imporve question and give it in details.
Pratik Bhuva 8-Nov-13 6:51am    
sorry , Can't get your actual problem.
anurag19289 8-Nov-13 10:25am    
unable to understand..improve your question

C#
Console.WriteLine("please enter start date");

string sStartdate = string.Empty;
//Input date
sStartdate = Console.ReadLine();

DateTime dStartDate;
//Parse the input to date time
DateTime.TryParse(sStartdate, out dStartDate);

//Display it
Console.Write(dStartDate);

//Wait for enter key hit (to hang the console window for a input)
Console.ReadLine();


// for miltiple entry use this solution ---------------------------------------------------

List<datetime> dtArray = new List<datetime>();

while (true)
{
Console.WriteLine("Enter date");
string sStartdate = string.Empty;
sStartdate = Console.ReadLine();

DateTime dStartDate;
if (DateTime.TryParse(sStartdate, out dStartDate))
{
dtArray.Add(dStartDate);
}

string sAns = "Y";
Console.WriteLine("Want to enter next (Y/N)?");

do
{
sAns = Console.ReadLine();

if (sAns.ToUpper() != "Y" && sAns.ToUpper() != "N")
Console.WriteLine("Invalid Input, Valid inputs are Y/N?");
} while (sAns.ToUpper() != "Y" && sAns.ToUpper() != "N");

if (sAns.ToUpper() == "N")
{
break;
}
}

foreach (var item in dtArray)
{
Console.WriteLine(item);
}

Console.ReadLine();
 
Share this answer
 
v4
Comments
Member 10381209 8-Nov-13 7:47am    
so in this way i can enter only one day but i want to enter array dinamyc array.do u know how to do that?
Amitava Bag (Kolkata) 8-Nov-13 9:14am    
I have updated, please check.
Always improve your answer, don't post multiple answers. Please delete this and add all these inside the first solution given by you.

Thanks,
Tadit
Try to take the input in a string (with Console.ReadLine) and then put it into array or list or direct convert to datetime (DateTime.TryParse).
 
Share this answer
 
Comments
Member 10381209 8-Nov-13 7:13am    
i didnot understand really,i am new in c# maybe that is reason ((
try this one

C#
int hour = 23;
var today = DateTime.Today;
var time = new DateTime(today.Year, today.Month, today.Day, hour, 0, 0);

C#
var time = DateTime.Today + TimeSpan.FromHours(hour);
 
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