I have this code to retrieve a date
var _Sdate = new Date(Date.parse($("#LSDate").val()));
It been loop thats why I got 2 dates.
And now I am getting this error:
.
I have tried to set DateTime date1
but I got also an error.
I have this code to retrieve a date
var _Sdate = new Date(Date.parse($("#LSDate").val()));
It been loop thats why I got 2 dates.
And now I am getting this error:
.
I have tried to set DateTime date1
but I got also an error.
This date format is not what a .Net DateTime object can parse, you actually have to make your date looks more like: 2011-03-21 13:26
Check this answer for expected Datetime data input to parse a string, there are multiple string representations taht can be parsed. (also in this MSDN doc, at section Converting strings to DateTime values)
Mon Aug 1 2016 00:00:00 GMT 0800 (China
... etc ... is nowhere near a valid DateTime.
Hence the invalid DateTime error on parsing.
Where are you getting this value from?
DateTime.Parse Method (String)
The .Net framework, when given a string, needs to understand how to turn that into a DateTime object, and it can't do that with what you've provided it.
Thanks for the support guys. I found a solution to while doing an experiment on my codes. I use this
var _Sdate = new Date(Date.parse($("#LSDate").val()));
var _EndDate = new Date(Date.parse($("#LEDate").val()));
var cbxAM = $('.cbox_leave_half').is(':checked');
var cbxPM = $('.cbox_leave_halfPM').is(':checked');
var IsAM, IsPM, date1 = "";
var _halfdayCount = "";
var x = 0;
var getfullhrAM = "12:00:00 AM"
var chkdateAM = "", chkdatePM = "";
if (parseInt(_hashalfday) > 0) {
while (_Sdate <= _EndDate) {
var fulldate = (_Sdate.getMonth() + 1) + "/" + _Sdate.getDate() + "/" + _Sdate.getFullYear();
var getcompile = fulldate + " " + getfullhrAM;
if (_Sdate != _EndDate) {
_halfdayCount = _halfdayCount + HalfDayrowsObj[x].HalfDay + ",";
date1 = date1 + getcompile + ",";
if (HalfDayrowsObj[x].HalfDay == true) {
if (cbxAM == true) {
chkdateAM = getcompile;
} else {
IsAM = false;
}
}
}
else {
_halfdayCount = _halfdayCount + HalfDayrowsObj[x].HalfDay;
NofDays = parseFloat(NofDays) + parseFloat('.5');
date1 = date1 + +HalfDayrowsObj[x].HalfDay;
}
x++;
_Sdate.setDate(_Sdate.getDate() + 1);
}
}
I will be pleased to offer my little js-function for getting any js date into acceptable format for C#, SQL Server and PHP,MYSql
var jsdate = new Date(Date.parse($("#LSDate").val()));
//jsdate is java-script date object
//Before you send it to use at server, plz make it a string as following
var _Sdate = getDateTimeString(_Sdate);
//Now you get _Ssdate acceptable for c#,sql it would be like '2016-08-01 02:13:06'
function getDateTimeString(dt) {
var dt = new Date();
var m = dt.getMonth() + 1;
var y = dt.getFullYear();
var d = dt.getDate();
var mm = dt.getMinutes();
var h = dt.getHours();
var s = dt.getSeconds();
if (m < 10)
m = "0" + m;
if (d < 10)
d = "0" + d;
if (h < 10)
h = "0" + h;
if (mm < 10)
mm = "0" + mm;
if (s < 10)
s = "0" + s;
return y + "-" + m + "-" + d + " " + h + ":" + mm + ":" + s;
}