date function changes in 2.2?

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:

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';

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

Why do you go through all that hassle?

Why not just use:

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:

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

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

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).

Looks like a bug to me.

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

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();

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.

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’.

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

Then for example in an SQL I use:

	"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.

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’

var vDate,
    vDate2;

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

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

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

The problem still exists in b2.

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

Whoops!

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

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';

for Christoph..

var vDate,
    vDate2;

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

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?

bug:(

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;

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

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:

Thanks!
Patrick

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

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

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

Does that mean, that

var date2;
date2 = date1;

is different from

var date2 = date1;

Thanks
Patrick