Page 1 of 1

Date from DatePicker control

Posted: 10 Feb 2016
by armin o
var d = fd.field('In_x0020_use_x0020_since').control('getDate');

gets me a:

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined


Calling Value() returns a string, which is not what i need. I need the Date Object.


What am i doing wrong?


Thanks,
Armin

Re: Date from DatePicker control

Posted: 10 Feb 2016
by rostislav
I assume you're trying to do this on a Display form? On a Display form you are only able to get a string out any field field type, so if you need a Date object, you'll have to create it yourself. Exact code will depend on what culture format your date is in, but essentially it would be something like this:

Code: Select all

var parts = fd.field('In_x0020_use_x0020_since').value().split('-');
var myDate = new Date(parts[0], parts[1]-1, parts[2]); // Note: months are 0-based

Re: Date from DatePicker control

Posted: 10 Feb 2016
by armin o
Thank you. We are dealing with german and english date formats, so here is what i came up with..



function asDate(dateString)

{

var startDate = {};

if (dateString.indexOf('.') != -1) {

var d = dateString.substring(0,2);

var m = dateString.substring(3,5)-1;

var y = dateString.substring(6,10);

var ho = dateString.substring(11,13);

var mi = dateString.substring(14,16);

startDate = new Date(y,m,d,ho,mi);

} else

{

debugger;

var dps = dateString.split(' ');

var dp = dps[0].split('/');



var d = dp[1];

var m = dp[0]-1;

var y = dp[2];

var ho = dps[1].substring(0,2);

var mi = dps[1].substring(3,5);

startDate = new Date(y,m,d,ho,mi);

}

return startDate;

}