Converting Unix Time to a Servoy Formatted Date

I am pulling data from a table that uses unix time and want to convert the unix time to a format that I can then plugin to the DATETIME column I have in Servoy.

Here’s my conversion method, but I get an error when I try to set it in a DATETIME column in Servoy.

function unix_epoch_to_date()
{
// converts date to unix epoch
if (arguments[0] === null || arguments[0] === '')
{
	return;
}

	var myDate = new Date( arguments[0] *1000);
	var thyTime = myDate.toTimeString()
	var thyDate = myDate.toDateString()	
	var thyFinalDate = thyDate + " " + thyTime
	return thyFinalDate
	
}

What am I doing wrong?

Chico

At first glance I’d say that you are using 3 equal signs (===) instead of 2 (==) in your if statement, try to turn the debugger on and see if the code is actually executed.

Your method returns a string, not a datetime.

I’m not sure why you make it a string in the first place, but I think you can just use this instead:

function unix_epoch_to_date()
{
// converts date to unix epoch
if (arguments[0] === null || arguments[0] === '')
{
   return;
}

	var myDate = new Date( arguments[0] *1000);
	return myDate;
}

ngervasi:
At first glance I’d say that you are using 3 equal signs (===) instead of 2 (==) in your if statement

Using 3 equal signs is valid javascript, see this for example: JavaScript Comparison and Logical Operators

Wow, never used that one, I never stop from learning :)

Anyway I’d say that

if(!arguments[0])

should be enough.