# date function changes in 2.2?

**URL:** <https://forum.servoy.com/t/date-function-changes-in-2-2/3399>\
**Category:** Classic Servoy\
**Created:** [January 7, 2005, 5:03pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399 "2005-01-07T17:03:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Cain](https://forum.servoy.com/u/Cain)\
**Post date:** [January 7, 2005, 5:03pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/1 "2005-01-07T17:03:40Z")

</div>

I have a bit of code that I use to create a date range for searching. It uses two global date fields, datetime1 and datetime2.

It’s been in place for some time now and seemed to work fine. Since upgrading to 2.2, though, the times don’t get set. Has there been a change (intentional or otherwise) to the date functions?

Here’s the code:

```auto
controller.saveData();
// set datetime1 to the first second of the day.
var d1 = globals.datetime1;
d1.setHours(00);
d1.setMinutes(00);
d1.setSeconds(00);
var df1 = utils.dateFormat(d1, 'MM-dd-yyyy HH:mm:ss');
// set datetime2 out to the last second of that day.
var d2 = globals.datetime2;
d2.setHours(23);
d2.setMinutes(59);
d2.setSeconds(59);
var df2 = utils.dateFormat(d2, 'MM-dd-yyyy HH:mm:ss');
// parse all this into a queryString
globals.queryString = df1+'...' + df2+'|MM-dd-yyyy HH:mm:ss';

```

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [January 7, 2005, 6:37pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/2 "2005-01-07T18:37:46Z")

</div>

I hope theres not a problem, I have alot of code to fix if so

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [January 7, 2005, 7:12pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/3 "2005-01-07T19:12:22Z")

</div>

Why do you go through all that hassle?

Why not just use:

```auto
controller.find()
startDateTime = '1-1-2004...1-30-2004|MM-dd-yyyy'
controller.search()

```

If you want to search for a SINGLE DATE - then you can either put in the time components - or MUCH EASIER - put a “#” before your find string:

```auto
controller.find()
startDateTime = '#1-1-2004|MM-dd-yyyy'
controller.search();

```

---

<div class="post-metadata">

**Author:** ![Cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Cain](https://forum.servoy.com/u/Cain)\
**Post date:** [January 7, 2005, 7:37pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/4 "2005-01-07T19:37:22Z")

</div>

Bob,

I misspoke. They’re not date fields, they’re datetime fields, so ‘1-1-2004…1-30-2004|MM-dd-yyyy’ doesn’t include 1-30-2004. I got this method from Erich at [Date Format search - Classic Servoy - Servoy Community](http://forum.servoy.com/viewtopic.php?t=3442)

I could use the # for single dates, but I’d like it to work both ways, like this did up until I went to 2.2.

If there’s a shorter way to do what I’m doing, that’s great, and I’m interested, but that won’t fix the functions, or tell me how to properly use them when I need them.

The relevant point is this: setHours, etc. doesn’t seem to be working any more. Running this produces a queryString with unchanged times (set to zero for dates I’ve entered, and current time where I’ve set the current timestamp).

---

<div class="post-metadata">

**Author:** ![bcusick](https://avatars.discourse-cdn.com/v4/letter/b/ed8c4c/32.png) [@bcusick](https://forum.servoy.com/u/bcusick)\
**Post date:** [January 7, 2005, 7:45pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/5 "2005-01-07T19:45:22Z")

</div>

Looks like a bug to me.

I was able to duplicate your results in my own testing.

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [January 7, 2005, 7:54pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/6 "2005-01-07T19:54:39Z")

</div>

what if you have to do a global search with many variables

//Convert date range fields if not null  
if (globals.Date1)  
{  
var d1 = globals.Date1  
d1.setHours(00)  
d1.setMinutes(00)  
d1.setSeconds(00)  
var df1 = utils.dateFormat(d1, ‘MM-dd-yyyy hh:mm:ss’)  
}

if(globals.Date2)  
{  
var d2 = globals.Date2  
d2.setHours(00)  
d2.setMinutes(00)  
d2.setSeconds(00)  
var df2 = utils.dateFormat(d2, ‘MM-dd-yyyy hh:mm:ss’)  
}

// validate date fields  
if (globals.Date1 == null && globals.Date2)  
{  
plugins.dialogs.showInfoDialog(‘Warning’, ‘You must enter a start and end date’,‘OK’);  
return  
}  
if (globals.Date2 == null && globals.Date1)  
{  
plugins.dialogs.showInfoDialog(‘Warning’, ‘You must enter a start and end date’,‘OK’);  
return  
}

//find, insert, search  
controller.find()  
// This code removes the operators from ship return date if there is no date criteria  
if (globals.Date1 && globals.Date2)  
{  
shipping\_date\_returned = df1+ ‘…’ + df2 + ‘|MM-dd-yyyy hh:mm:ss’  
}  
else  
{  
shipping\_date\_returned = null  
}  
tracking\_number = globals.Text1  
transaction\_type = globals.Text2  
equipment\_classification = globals.Text3  
tse\_number = globals.Text4  
return\_status = globals.Text5  
inventory\_id = globals.Integer1  
account\_id = globals.Integer2  
if (globals.Text6) {  
model = ‘%’ + globals.Text6 + ‘%’  
}  
application.closeFormDialog();  
controller.search()  
forms.CSMiscServicesSearchListing.controller.show()  
globals.Number3 = controller.getMaxRecordIndex();

---

<div class="post-metadata">

**Author:** ![Cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Cain](https://forum.servoy.com/u/Cain)\
**Post date:** [January 7, 2005, 7:59pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/7 "2005-01-07T19:59:20Z")

</div>

Thanks, Bob. 'least I know I’m not nuts! (well, not on this count, anyhow).

Hope it’s a quick fix. I’m kinda dependent on this right now.

---

<div class="post-metadata">

**Author:** ![john.allen](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@john.allen](https://forum.servoy.com/u/john.allen)\
**Post date:** [January 9, 2005, 2:53am UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/8 "2005-01-09T02:53:59Z")

</div>

Not that this necessarily helps in this context but I have found that in  
working with dates I really prefer to do almost everything directly in the  
SQL backend database. In my case for instance I always need to have  
today’s date at hand and bring up records based on that. After messing  
around with the whole ’ 00:00:00’ and ’ 23:59:59’ stuff I found it easiest  
to simply create a global today field when the user first logs in. Thus I do  
the following in the global method in which g\_Today is a global field set to  
the default value ‘now’.

```auto
globals.g_Todaysdate = utils.dateFormat(globals.g_Today, 'MM/dd/yyyy');

```

Then for example in an SQL I use:

```auto
	"WHERE date_created >= '" + globals.g_Todaysdate + " 00:00:00'" +

```

I could change the ’ 00:00:00’ into a global too (the ‘end’ time ’ 23:59:59’  
for that matter) but haven’t bothered. In cases where you need a  
dynamic value depending on the record/column selected a similar thing  
can happen tied to onShow, onRecordSelection or whatever. For elapsed  
time and ranges between dates I then use either the ‘datediff’ function or  
‘BETWEEN’. The thing I felt was that Servoy was turning these things into  
SQL statements anyway so one might as well do it straight away: less  
code, fewer variables.

---

<div class="post-metadata">

**Author:** ![Christoph](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@Christoph](https://forum.servoy.com/u/Christoph)\
**Post date:** [January 11, 2005, 3:36pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/9 "2005-01-11T15:36:23Z")

</div>

The problem that I have is, that both the variables will get the value I set in ‘variable.setMinutes(value)’.

In the following example vDate and vDate2 have unexpectedly (?) the same value: ‘2005-01-10 23:59:00’

```auto
var vDate,
    vDate2;

vDate = new Date(2005, 0, 10, 10, 0, 0);

vDate2 = vDate;
vDate2.setHours(23);
vDate2.setMinutes(59);

```

---

<div class="post-metadata">

**Author:** ![Cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Cain](https://forum.servoy.com/u/Cain)\
**Post date:** [January 11, 2005, 6:14pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/10 "2005-01-11T18:14:23Z")

</div>

Is this fixed in b2? I didn’t see it in the list.

---

<div class="post-metadata">

**Author:** ![Christoph](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@Christoph](https://forum.servoy.com/u/Christoph)\
**Post date:** [January 11, 2005, 6:21pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/11 "2005-01-11T18:21:56Z")

</div>

The problem still exists in b2.

---

<div class="post-metadata">

**Author:** ![Cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Cain](https://forum.servoy.com/u/Cain)\
**Post date:** [January 11, 2005, 7:23pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/12 "2005-01-11T19:23:13Z")

</div>

I have a report that uses the code I posted here. It’s in production and really needs to work. Can anyone suggest an alternative I could use until this is fixed?

The user enters a start and end date into globals.datetime1 and globals.datetime2, respectively.

I need to put those dates together into a string for searching the datetime in the form, which is formatted MM/dd/yyyy.

The string should find the range of dates, inclusive (including the end date).

TIA

---

<div class="post-metadata">

**Author:** ![Cain](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Cain](https://forum.servoy.com/u/Cain)\
**Post date:** [January 11, 2005, 7:57pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/13 "2005-01-11T19:57:30Z")

</div>

Whoops!

Nevermind. Closer reading of this thread led me to a simpler way:

```auto
var df1 = utils.dateFormat(globals.datetime1, 'MM/dd/yyyy')+ ' 00:00:00';
var df2 = utils.dateFormat(globals.datetime2, 'MM/dd/yyyy')+ ' 23:59:59';
globals.queryString = df1+'...' + df2+'|MM/dd/yyyy HH:mm:ss';

```

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [January 12, 2005, 9:47am UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/14 "2005-01-12T09:47:10Z")

</div>

for Christoph..

```auto
var vDate,
    vDate2;

vDate = new Date(2005, 0, 10, 10, 0, 0);
vDate2 = new Date(2005, 0, 10, 23, 59, 0);

```

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [January 12, 2005, 10:28am UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/15 "2005-01-12T10:28:22Z")

</div>

Maarten,

I know that works. But how is it possible that vDate and vDate2 in Christoph’s example have the same value at the end?

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [January 12, 2005, 11:34am UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/16 "2005-01-12T11:34:37Z")

</div>

bug:(

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 13, 2005, 9:20pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/17 "2005-01-13T21:20:22Z")

</div>

because if you do this:

var date2 = date1;

then anything you do on date2 also happens on data1  
because those 2 dates are the exact same objects..

you don’t create a copy if you do this: date2=date1;

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [January 28, 2005, 7:53pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/18 "2005-01-28T19:53:16Z")

</div>

Johan,

I am not sure if I get this right. I have the same problem when passing a foundset from one method to another. If you do something like

```auto
var fs = foundset; // fs gets let's say a foundset of two records
controller.loadAllRecords() // now fs changes to the new foundset

```

I sort of see that I only passed a reference to an object “foundset” to fs somehow, but I don’t understand exactly why this happens and how you come around it. Unfortunately, I am not a studied programmer. If you have the time… ![:lol:]( "Laughing")

Thanks!  
Patrick

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [January 30, 2005, 9:49pm UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/19 "2005-01-30T21:49:42Z")

</div>

you have to clone/copy the foundset if you want to store a copy for later use and modify the other. see controller.duplicateFoundset()

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 20, 2005, 10:17am UTC](https://forum.servoy.com/t/date-function-changes-in-2-2/3399/20 "2005-04-20T10:17:43Z")

</div>

Johan, the cloning of objects/foundsets etc. seems to be important in some areas. I am not sure that I fully understand how to do this. You write

```auto
you don't create a copy if you do this: date2=date1;

```

Does that mean, that

```auto
var date2;
date2 = date1;

```

is different from

```auto
var date2 = date1;

```

Thanks  
Patrick

[Next page](https://forum.servoy.com/t/date-function-changes-in-2-2/3399.md?page=2)
