# Converting Unix Time to a Servoy Formatted Date

**URL:** https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834
**Category:** Classic Servoy
**Created:** [June 26, 2009, 4:40pm UTC](https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834 "2009-06-26T16:40:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chico](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@chico](https://forum.servoy.com/u/chico)
#### Post date: [June 26, 2009, 4:40pm UTC](https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834/1 "2009-06-26T16:40:48Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

### Author: ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)
#### Post date: [June 26, 2009, 11:52pm UTC](https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834/2 "2009-06-26T23:52:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)
#### Post date: [June 27, 2009, 7:15am UTC](https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834/3 "2009-06-27T07:15:08Z")

</div>

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:

```auto
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;
}

```

---

<div class="post-metadata">

### Author: ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)
#### Post date: [June 27, 2009, 7:24am UTC](https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834/4 "2009-06-27T07:24:03Z")

</div>

> 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](http://www.w3schools.com/JS/js_comparisons.asp)

---

<div class="post-metadata">

### Author: ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)
#### Post date: [June 27, 2009, 10:52am UTC](https://forum.servoy.com/t/converting-unix-time-to-a-servoy-formatted-date/10834/5 "2009-06-27T10:52:55Z")

</div>

Wow, never used that one, I never stop from learning ![:)]( "Smile")

Anyway I’d say that

```auto
if(!arguments[0])

```

should be enough.
