locked
get date and time from User, merge them and save in a Date/Time field in database RRS feed

  • Question

  • User-1693623980 posted

    Hi,

    I need to show news that they start date is greater than for example 1/18/2014 1:52:55 PM

    how can we get date and time from User, merge them and save in a Date/Time field in database.

    I can get date with the help of datepicker but what about time? and for example if I get time via dropdownlist how can I merge this time with that date in a Date/Time field?

    thanks

    Saturday, January 18, 2014 5:55 AM

Answers

  • User-837620913 posted

    There is a Date and Time picker jQuery plugin available here: http://trentrichardson.com/examples/timepicker/

    Download is in the Getting Started tab. Examples are in the Examples tab.

    Github repository is here: https://github.com/trentrichardson/jQuery-Timepicker-Addon

    In your ViewModel the property should be a DateTime.

    In JavaScript, make sure you run the following code before submitting the JSON (assuming AJAX post, normal post model binding should be fine):

    var dateTimeValue = $('#IdOfDateTimeHere').val();    
    new Date(dateTimeValue).toJSON()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 18, 2014 6:15 AM

All replies

  • User-837620913 posted

    There is a Date and Time picker jQuery plugin available here: http://trentrichardson.com/examples/timepicker/

    Download is in the Getting Started tab. Examples are in the Examples tab.

    Github repository is here: https://github.com/trentrichardson/jQuery-Timepicker-Addon

    In your ViewModel the property should be a DateTime.

    In JavaScript, make sure you run the following code before submitting the JSON (assuming AJAX post, normal post model binding should be fine):

    var dateTimeValue = $('#IdOfDateTimeHere').val();    
    new Date(dateTimeValue).toJSON()

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 18, 2014 6:15 AM
  • User-1693623980 posted

    Thanks Darrell

    one thing I must say before

    I can't use Gregorian date datetimepickers (I have to use solar Date), here there is some datepicker but as I know there isn't any date and time picker (both date and time) in solar date.

    so I have to give time and date seperately.

    so assume I get this date using datepicker 1/18/2014

    and I get this time using datetime picker that  you suggest 12:46

    how can we combine and save them in Date/Time field in table?

    Edit:

    I tried this

     string date = "1/18/2014";
            string Time = "12:46";
            string dT = date + " "  + Time;
    
            DBase.ExecuteNoneQuery(System.Data.CommandType.Text, "Insert into Table1 (testDateTime) values (@testDateTime)", new OleDbParameter[]{
                new OleDbParameter("@testDateTime",Convert.ToDateTime(dT))
            });

    and the result was what I wanted: 1/18/2014 12:46:00 PM

    but I think my way isn't standard way. (If you think so please let me know)

    thanks

    Saturday, January 18, 2014 6:59 AM