I was using a time picker which returns the date and time together. This was making for me problems since i am comparing this value with a database column of type time only. Tried another free time picker control but when assigning it to a repeater and when it comes to define the data source of repeater and writting the SQL Query I cant select the time picker control from the drop down list simply because it is not available.
any other time picker controls with a stylish look and effecient?
Regards.
I'm not sure about a control which fits your exact needs but you should be able to convert the .net DateTime to a TimeSpan which you could then compare against the sql Time datatype
DateTime myDateTime = DateTime.Now;
TimeSpan myTimeSpan = new TimeSpan(myDateTime.Hour, myDateTime.Minute, myDateTime.Second, myDateTime.Millisecond);
Related
I'm trying to work with the ASP calendar control and (for starters) highlight the specific days on the calendar that matches DueDate in the 'task' table. I know how to highlight a cell using the DayRender event, but how do I do this in accordance to the database table?
Would then also like to be able to click on the highlighted cell and see details of the task associated to that date in some sort of box next to the calendar.
Any pointers on how I can solve this?
Pseudo-code:
Determine your desired date range (probably a certain month)
Read all the tasks that have due dates within that date range (probably need Name and DueDate at least)
In your DayRender handler you check if current day's date exists in the loaded tasks's due dates, if it does, highlight it with the color of your choice
In you SelectionChanged handler you obtain the selected day's date, and look through the loaded list of tasks for any tasks that have that date as their due date, and populate whatever box with those tasks.
I know this question is on SO a few times already but I cannot find a working or suitable answer.
I want a date picker which includes a time picker. I don't want any fancy frills etc, just something that works. Preferably one control I can drag into the tool box in VS, register at the top and work with. I have been playing around with many versions the last few days and I can't get one to work. They normally seem to include too many files for me or something stupid. A project I am working on now hinges on this stupid thing so any advice would be welcome. I have previously managed to get a calendar control and put some validation on a text-box to pick times. However I cannot take both of these values and enter them into my database as on Date-time field because when I try to use "Selected-date" to get the time it naturally says that text-boxes cannot be members of the "Selected-date" property.
As I have a calendar control in to pick the date and a validated textbox to type in the time I tried to use the following code.
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim time As String() = txtTime.SelectedDate.ToString().Trim().Split(" "C)
Dim [date] As String() = cldDate.SelectedDate.ToString().Trim().Split(" "C)
Dim datetime__1 As String = [date](0) & " " & time(1) & time(2)
Dim DateTimeValue As DateTime = DateTime.Parse(datetime__1)
Response.Write(DateTimeValue.ToString())
' Update database with DateTimeValue.
End Sub
The code txtTime.SelectedDate.ToString() is a problem here. It says that SelectedDate is not a supported member of textbox. This is code that I have came across. I'm pretty new to coding.
You could create a new instance of the DateTime structure. The DateTimePicker.SelectedValue returns a Nullable(Of DateTime), so you can use the values of this to create a new DateTime (along with the values from your textboxes).
For example:
Dim myDateTime As New DateTime(cldDate.SelectedDate.Year, cldDate.SelectedDate.Month, cldDate.SelectedDate.Day, HourValue, MinuteValue, 0)
Just replace HourValue and MinuteValue with your values from your textboxes. Note you should convert these to Integers.
Note the 0 at the end represents seconds.
This should save to the database fine.
For more info on DateTime see here.
if jQuery is an option i would look at this plug in
clean and easy to implement
You don't mention whether a commercial product would be an option for you.
We are using telerik's RadDateTimePicker in our projects (and there are certainly other commercial products). See this page for a demo of the datetime picker control.
I am try storing my date values in UTC format into my SQL Server DB and then convert them to local time for displaying, seem to work fine, I can see that my DB date values stored are different(I presume it's converted to UTC already), retrieving it and display is also accurate until I try to test a different timezone by changing it in the Date and Time option(right bottom of Windows time settings in the task bar) so to "migrate" myself. Apparently, the dates still remain as I am in my own country even though the timezone which I changed to has a 3 hrs difference.
Can somehow please advice on a way to test the date display on a different timezone?
Thanks.
Storing date values to SQL Server:
DateTime dateFrom = DateTime.Parse(startDateTime).ToUniversalTime();
DateTime dateTo = DateTime.Parse(endDateTime).ToUniversalTime();
parameters.Add(new SqlParameter("#StartDateTime", dateFrom));
parameters.Add(new SqlParameter("#EndDateTime", dateTo));
Retrive from DB and Display:
DateTime date = DateTime.UtcNow.ToLocalTime();
date = DateTime.Parse(dr["StartDateTime"].ToString()).ToLocalTime();
litDateTimeFrom.Text = date.ToString("dd MMM yy hh:mm tt");
date = DateTime.Parse(dr["EndDateTime"].ToString()).ToLocalTime();
litDateTimeTo.Text = date.ToString("dd MMM yy hh:mm tt");
First thing, I am assuming that you have changed time zone information on the server machine (because that is what will be used in ToLocalTime method). If not then that's what you need to do first for testing.
Secondly, have you tried restarting IIS (or your web application) after changing the system time zone? That is necessary because time-zone information could have been cached within .NET framework (in TimeZoneInfo class).
Said all that, to me, this does not make sense. Typically, time-zone information need to flow from user (client) machine because you want to show user local time (as relevant to his time-zone). So it would mean that you need to figure out the current user's time zone based on a) culture info from browser or b) what is stored in his profile data (perhaps country or actual time-zone) c) similar scheme. Once, user time-zone is known, you can use
TimeZoneInfo class to convert UTC time to corresponding local time.
I am working in C++ .net. I have a custom control that shows the contents of a dataBase with a bindingsource in between. I use labels in the control to bind the text property to the data in the dataset through a bindingsource with the following code:
mycontrol->Controls[i]->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text",
this->bindingSourceRelRev_Data, mycolumn,true, System::Windows::Forms::DataSourceUpdateMode::OnValidation,
nullptr, L"t")));
Please, note that the code is an excerpt of a loop that iterates on all the controls, therefore the control[i], which would be the label control, and the variable mycolumn, which would be the column of the dataset to be binded to. It works fine apart of an unwanted behaviour that I haven't yet found the way to change.
The sofware runs in different parts of the world but the records must be in local time. The database stores the time in localtime as a DateTime value but the dataBinding interprets it as UTC and shows the time in the label with the timezone difference applied. For example, if the data is 24/06/2012 16:40, it will show 24/06/2012 22:40 in a 4 hours difference time zone.
I need it to show just the value as it was stored, without changes.
I can think of different ways to go arround, but non elegant:
-capture the text update event of the label and un-do the change...
-Store the date as String in the DB...
-fill manually the labels...
-...
If I bind without formating, it will not change the value, but then I have the raw datetime string on the label...
Please, any magic I am missing in the binding so that it will not assume it has to change the time zone?
Thank you very much in advance!
Adan
well, it seems that the problem was not actually on the binding but in the dataset itself. The columns' property DateTimeMode was set as undefinedlocal and this was serializing the dataimput and converting it to the local time of the machine viewing the data. Just changed the property to undefined and it works now as I wanted, just taking the date from the data unmodified.
I was confused by the documentation on the format provider for DateTime, which states that it serializes the date. Perhaps I missunderstood it... It actually doesn't.
Thank you very much anyway!
I want to display time starting from 8AM To 7PM With interval 15 minutes. So:
8.15AM
8.30AM
8.45AM
9AM
9.15AM
9.30AM
In a dropdownlist. Is there any built-in control in ASP.NET other than dropdownlist to display time?
You can find something at eworldui or codeproject
Doing a search for "asp.net time picker" will reveal some others, too.
There is nothing native to display time, you'll need to do it in a drop down list. From a usability perspective, I'd be inclined to break it into one list for hour and another for the 15 minute interval. Depending on your design, you may have the values for the lists stored in a database so can just bind the tables to the lists or alternatively just implement a loop within the code behind and add the list items programmatically.
To fill your dropdownlist, you could try something like:
Dim dt As DateTime = #8:00:00 AM#
For i As Integer = 0 To 44
DropDownList1.Items.Add(dt.ToString("hh:mmtt"))
dt = DateAdd(DateInterval.Minute, 15, dt)
Next