Solved

datetime set

Posted on 2013-11-21
3
249 Views
Last Modified: 2013-11-25
This code below selects the date by the user and as per selection returns the selected date but the
time is reset to 12:00AM.For example if user select o6/11 the return is "
06-11-2013 00:00" but i want the time to reflect the current time from the server...

private void CalenderDate_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
        {
            List<string> strdet = new List<string>();
            strdet.Add("essaetechnologyspvtlimited");
            strdet.Add("dev");
            strdet.Add("essaecrm@live.in");
            strdet.Add("Essae@123");
            strdet.Add("crm5");
            GridViewData gdv = new GridViewData();
            gdv.dtx(org.getOrders((System.DateTime)CalenderDate.SelectedDate), strdet);
            gdv.ShowDialog();
        }
0
Comment
Question by:Moizsaif123
3 Comments
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 167 total points
ID: 39665688
I would create an extension method for this.
Look at the example below
public static DateTime WithCurrentTime(this DateTime input)
{
	DateTime now = DateTime.Now;

	return new DateTime(input.Year, input.Month, input.Day, now.Hour, now.Minute, now.Second);
}

Open in new window

Usage :
((System.DateTime)CalenderDate.SelectedDate).WithCurrentTime()

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 167 total points
ID: 39665746
((System.DateTime)CalenderDate.SelectedDate).Add ( new TimeSpan ( DateTime.Now.TimeOfDay.Ticks ) )
0
 
LVL 7

Assisted Solution

by:keustermans
keustermans earned 166 total points
ID: 39668634
Hi There,

Use a DateTimePicker control

and do the following:

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
     string a = "a";

     System.DateTime dt = ((DateTimePicker)sender).Value;
}
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.

839 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