Date time: All about

Calendar

ASP.NET – Telerik

[js]

[/js]
[js]
// Get selected date
var StartDatePicker = $find(“<%=txtStartDate.ClientID %>”);
var StartDate = StartDatePicker.get_dateInput().get_selectedDate();
[/js]
[js]
// Fix selected date
var nextDateTime = new Date(StartDate);
nextDateTime.setHours(StartDate.getHours() + 1);
radEndTimePicker.set_selectedDate(nextDateTime);
[/js]

JS – All about date and time

How to add a day?

[js]
var dayNo = 1;
var StartDateFixed = new Date(StartDate.setTime( StartDate.getTime() + dayNo * 86400000 ));
[/js]

What is standard format of Date/ time format

It is ‘YYYY-MM-DD HH:MM’, if using different format than this, some function such as ‘Date.parse()’ won’t work correctly.
For example, [js]alert(Date.parse(‘8/03/2017 00:00’))[/js] returns ‘NaN’

How to get current date with the format of dd/mm/yyyy hh:mm:ss

[js]
var today = new Date();
let created_date =
today.getDate()
+ “/” + today.getMonth()+1
+ “/” + today.getFullYear()
+ ” ” + today.getHours()
+ “:” + today.getMinutes()
+ “:” + today.getSeconds()
[/js]

How to get time format as “Thu, 15 Feb 2018 00:57:11 GMT” which can be passed as DateTime format for SQL Server API

[js]
var strDate = new Date();
alert((new Date(strDate)).toUTCString());
[/js]

How to calculate date time in the past basing on the number of days

[js]
function calculateStartEndDate(numberOfDay)
{
var currentdate = new Date();
var startDay = currentdate.getDate();
var startMonth = currentdate.getMonth() + 1;
var startYear = currentdate.getFullYear();

var days = numberOfDay;
startDay = startDay – days;
if (startDay <= 0) { startMonth = startMonth – 1; while (startMonth >= 0)
{
switch (startMonth)
{
case 0: // last year
startDay = 31 + startDay;
startMonth = 12;
startYear–;
break;
case 1:
startDay = 31 + startDay;
break;
case 2:
startDay = 28 + startDay;
break;
case 3:
startDay = 31 + startDay;
break;
case 4:
startDay = 30 + startDay;
break;
case 5:
startDay = 31 + startDay;
break;
case 6:
startDay = 30 + startDay;
break;
case 7:
startDay = 31 + startDay;
break;
case 8:
startDay = 31 + startDay;
break;
case 9:
startDay = 30 + startDay;
break;
case 10:
startDay = 31 + startDay;
break;
case 11:
startDay = 30 + startDay;
break;
case 12:
startDay = 31 + startDay;
break;
default:
break;
}

if (startDay > 0)
{
break;
}
else
{
startMonth–;
if (startMonth == 0)
{
// Last year
startYear–;
startMonth = 12;
}
}
}
}

// Set Start Date
var months = [“Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”];
var strDate = startDay + ‘ ‘ + months[parseInt(startMonth)-1] + ‘ ‘ + startYear;
$(“#txtStartDate_dateInput”).val(strDate);
document.getElementById(“txtStartDate_dateInput”).focus();
document.getElementById(“txtStartDate_dateInput”).blur();
}
[/js]

Be the first to comment

Leave a Reply

Your email address will not be published.


*