# Time problem

**URL:** <https://forum.servoy.com/t/time-problem/8725>\
**Category:** Classic Servoy\
**Created:** [February 12, 2008, 11:23am UTC](https://forum.servoy.com/t/time-problem/8725 "2008-02-12T11:23:35Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 12, 2008, 11:23am UTC](https://forum.servoy.com/t/time-problem/8725/1 "2008-02-12T11:23:35Z")

</div>

I have 3 datetime fields: begin, end and interval

I would like to build a valuelist eg.

begin = 08:30  
end = 17:00  
interval = 00:30 (30 minutes)

valuelist:  
08:30  
09:00  
09:30 etc.

No matter what I try I can’t increase the begin time.

Can somebody please help? ![:?]( "Confused")

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [February 12, 2008, 11:38am UTC](https://forum.servoy.com/t/time-problem/8725/2 "2008-02-12T11:38:14Z")

</div>

this is a little too little information.

Do the other 2 fields work?

Are you using formatting on all three?  
What datatype do you use on the fields?

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 12, 2008, 12:11pm UTC](https://forum.servoy.com/t/time-problem/8725/3 "2008-02-12T12:11:33Z")

</div>

Hi Irene,

You just want a popup with time values ?  
So the date part of the datetime fields should be ignored, right?

Assuming your fieldnames are ‘begin’, ‘end’ and ‘interval’ your code could look like this:

```auto
var dValue = new Date(begin),
    dEnd = new Date(dValue.getFullYear(),dValue.getMonth(),dValue.getDate(),end.getHours(),end.getMinutes(),0),
    aValuelist = new Array(),
    dInterval1 = new Date(dValue.getFullYear(),dValue.getMonth(),dValue.getDate(),0,0,0),
    dInterval2 = new Date(dValue.getFullYear(),dValue.getMonth(),dValue.getDate(),interval.getHours(),interval.getMinutes(),0),
    nInterval = dInterval2-dInterval1;

while ( dValue <= end )
{
    aValuelist.push(utils.dateFormat(dValue, 'HH:mm'));
    dValue.setTime(dValue.getTime()+nInterval);
}

application.output(aValuelist.join("\n"));// debug

```

As you see I make sure that since we do work with date objects that all date values (year/month/day) are the same.  
Also to get the interval in milliseconds I need to have a date object that starts at midnight and substract that from the interval date object.  
This way the date itself won’t have any effect and I can calculate with the milliseconds.  
The resulting array you can use directly in the setValuelistItems() function.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 12, 2008, 1:55pm UTC](https://forum.servoy.com/t/time-problem/8725/4 "2008-02-12T13:55:49Z")

</div>

Hi Robert,

thanks, it surely helped, the application output is exactly what I had in mind. But for some reasons the format of the valuelist is not the same.

Although the field is formatted as HH:mm, the valuelist shows the unformatted values (1970-01-01 08:30:00:0).

Is there an other way to format valuelists?

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 12, 2008, 2:06pm UTC](https://forum.servoy.com/t/time-problem/8725/5 "2008-02-12T14:06:51Z")

</div>

Hi Irene,

This is because you put the (string) value of the valuelist back in a datetime field. Only the time value is provided so it add the default date to it  
I assumed you don’t care about the date part because you wanted only to see the time bit.  
Maybe you should explain how you want to use this method.

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 14, 2008, 8:19am UTC](https://forum.servoy.com/t/time-problem/8725/6 "2008-02-14T08:19:43Z")

</div>

Hi Robert,

the idea is to let the user chose the hours and the interval he wants to see an reproduce that in all value lists.

So I would like a valuelist only with the time.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 14, 2008, 10:00am UTC](https://forum.servoy.com/t/time-problem/8725/7 "2008-02-14T10:00:44Z")

</div>

Hi Irene,

And where will you be using this valuelist ? I mean where are you gonna store these times ?  
Datetime fields ?

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 14, 2008, 10:06am UTC](https://forum.servoy.com/t/time-problem/8725/8 "2008-02-14T10:06:43Z")

</div>

it is a datetime field but it is formatted as HH:mm

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 14, 2008, 10:11am UTC](https://forum.servoy.com/t/time-problem/8725/9 "2008-02-14T10:11:38Z")

</div>

Hi Irene,

You should realise that formatting property (in this case) is for display purposes only. In the database it will also store the data part.  
When you don’t provide it then it will use the date 1970-01-01.  
So if you don’t use the date part anyway then there is no issue at all.  
When you do need a (current?) date in those fields then you need to work with onDataChange methods on these fields to set the date bit.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 14, 2008, 11:46am UTC](https://forum.servoy.com/t/time-problem/8725/10 "2008-02-14T11:46:08Z")

</div>

Hi Robert,

I don’t get it. I want to see only a time in that field, if I release the format I see the date and the time.

It is weird, I have 2 fields on that layout, both datetime both with the same valuelist. As soon as I release the formatting on one of them , I don’t see any values on the valuelist any more. ![:shock:]( "Shocked")

Do you get it ?.. I don’t

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 14, 2008, 12:01pm UTC](https://forum.servoy.com/t/time-problem/8725/11 "2008-02-14T12:01:33Z")

</div>

> irenem:  
> I don’t get it. I want to see only a time in that field, if I release the format I see the date and the time.

If you only want to see the time why would you remove the formatting ?

> irenem:  
> It is weird, I have 2 fields on that layout, both datetime both with the same valuelist. As soon as I release the formatting on one of them , I don’t see any values on the valuelist any more. :shock:

I don’t know how it exactly works internally but I can only assume that Servoy ‘knows’ what type of data this field can accept. And just a time is not a valid datetime value. So it doesn’t show the valuelist values.  
Maybe one of the Servoyans can shed more light on this.

But I am confused. Why is this a problem when you are only interested in the time values ?  
Or is this more a quest of ‘why is this working the way it works’ ?

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 14, 2008, 1:24pm UTC](https://forum.servoy.com/t/time-problem/8725/12 "2008-02-14T13:24:38Z")

</div>

Hi Robert,

The original problem is still the same.

> Although the field is formatted as HH:mm, the valuelist shows the unformatted values (1970-01-01 08:30:00:0).

I try desperately to show only the time in the value lists, so I’m playing around with the formats. But nothing seems to help.

The second question is more a “is this normal?” Sins I have upgraded my OS to OSX Leopard Sevoy does strange things.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [February 14, 2008, 1:59pm UTC](https://forum.servoy.com/t/time-problem/8725/13 "2008-02-14T13:59:54Z")

</div>

Hi Irene,

Here are 2 screenshots of a valuelist with (string) time values as you would get from the method I posted in this thread.  
Top field has displaytype Combobox with a valuelist attached. Also the formatting HH:mm is applied.  
You see that the valuelist shows the time values and the combobox does too.  
Underneath that combobox you see the same field without formatting.

Servoy Developer  
Version 3.5.3-build 516  
Java version 1.6.0\_04-b12-45-optimized (Mac OS X)  
and  
Java version 1.5.0\_13-119 (Mac OS X)  
Mac OS X 10.5.2

Isn’t this what you want ?

 ![Picture 2.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/2X/7/7d6820750645a31d19ba1283568fd42b3d9a337b.png)

 ![Picture 1.png](https://canada1.discourse-cdn.com/flex010/uploads/servoy/original/1X/2464a54e2c122c735533287db735c8e2fabaf53b.png)

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [February 14, 2008, 2:31pm UTC](https://forum.servoy.com/t/time-problem/8725/14 "2008-02-14T14:31:09Z")

</div>

Than you thank you thank you, this is exactly what I want.

I didn’t think about combobox because the field should be editable, but I will duplicate the field and make it a combobox.
