Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.databases.filemaker > #2464 > unrolled thread
| Started by | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| First post | 2015-11-03 01:05 -0800 |
| Last post | 2015-11-04 01:23 -0800 |
| Articles | 8 — 3 participants |
Back to article view | Back to comp.databases.filemaker
Problem With Dates in a Script csampson@inetworld.net (Charles H. Sampson) - 2015-11-03 01:05 -0800
Re: Problem With Dates in a Script clkaufmann@gmx.ch (Christoph Kaufmann) - 2015-11-03 10:26 +0100
Re: Problem With Dates in a Script Helpful Harry <HelpfulHarry@BusyWorking.com> - 2015-11-04 08:57 +1300
Re: Problem With Dates in a Script clkaufmann@gmx.ch (Christoph Kaufmann) - 2015-11-03 22:15 +0100
Re: Problem With Dates in a Script csampson@inetworld.net (Charles H. Sampson) - 2015-11-03 20:23 -0800
Re: Problem With Dates in a Script Helpful Harry <HelpfulHarry@BusyWorking.com> - 2015-11-04 18:37 +1300
Re: Problem With Dates in a Script csampson@inetworld.net (Charles H. Sampson) - 2015-11-03 18:58 -0800
Re: Problem With Dates in a Script (Solved) csampson@inetworld.net (Charles H. Sampson) - 2015-11-04 01:23 -0800
| From | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| Date | 2015-11-03 01:05 -0800 |
| Subject | Problem With Dates in a Script |
| Message-ID | <1mdacbh.13bn8z3s523f7N%csampson@inetworld.net> |
I'm having trouble with a script that I have to manipulate dates in.
This is for FileMaker Pro 8.0v3 running on a G5 with OS X 10.5.8.
I have to calculated a date based on two other dates. One of those other
dates in in text format. I'll call it TDate. It comes to the script as a
parameter and is obtained with the script step
Set Variable [$TDate; Value:Get(ScriptParameter)]
The other of those dates is from a global field in the database and is
presumably in FileMaker's internal format for a date. I'll call it
DDate. It is always referred to as
Global Data::DDate
but for simplicity in the following I'll just call it DDate.
I use the Month, Day, and Year functions to obtain $TMonth, $TDay,
$TYear, etc.
Here's the problem. I have the following if-statement:
iI [$DYear < $TYear]
<do stuff 1>
Else if [$DMonth < $TMonth]
<do stuff 2>
Else
<do stuff 3>
End If
(DDate will always be be less than TDate,)
When I execute this script with DDate = 11/2/2014 and TDate = 1/2/2015,
it's <do stuff 3> that gets executed rather than <do stuff 1>. I have
custom dialogs immediately before and in each arm of the if-statement
that verify that the values are all what they should be.
Any ideas? I suspect that it is something having to do with implicit
type conversions (between number and text) or an invisible character in
TDate. Or it's something else entirely and I'm not able to see it
because of that peculiar blindness that strikes coders from time to
time.
If there are any syntax errors in the above code fragments, blame them
on my typing. They're not in the script, which was created using
ScriptMaker.
Thanks in advance.
Charlie
--
Nobody in this country got rich on his own. You built a factory--good.
But you moved your goods on roads we all paid for. You hired workers we
all paid to educate. So keep a big hunk of the money from your factory.
But take a hunk and pay it forward. Elizabeth Warren (paraphrased)
[toc] | [next] | [standalone]
| From | clkaufmann@gmx.ch (Christoph Kaufmann) |
|---|---|
| Date | 2015-11-03 10:26 +0100 |
| Message-ID | <1mdb3n0.clubbf16ua01rN%clkaufmann@gmx.ch> |
| In reply to | #2464 |
Charles H. Sampson <csampson@inetworld.net> wrote: > Set Variable [$TDate; Value:Get(ScriptParameter)] Try GetAsDate ( Get ( ScriptParameter ) ) -- Christoph Kaufmann http://clk.ch
[toc] | [prev] | [next] | [standalone]
| From | Helpful Harry <HelpfulHarry@BusyWorking.com> |
|---|---|
| Date | 2015-11-04 08:57 +1300 |
| Message-ID | <041120150857094318%HelpfulHarry@BusyWorking.com> |
| In reply to | #2465 |
In article <1mdb3n0.clubbf16ua01rN%clkaufmann@gmx.ch>, Christoph Kaufmann <clkaufmann@gmx.ch> wrote: > Charles H. Sampson <csampson@inetworld.net> wrote: > > > > Set Variable [$TDate; Value:Get(ScriptParameter)] > > Try GetAsDate ( Get ( ScriptParameter ) ) Yep, the text-date will need to be converted into a proper date-date before it can be used with the Date functions (Day, Month, Year) or compared against other proper date-dates. If the GetAsDate function doesn't work, you'll have to do the conversion quasi-manually within the script by parsing the text-date using the "/" character as the delimiter for each part. Helpful Harry :o)
[toc] | [prev] | [next] | [standalone]
| From | clkaufmann@gmx.ch (Christoph Kaufmann) |
|---|---|
| Date | 2015-11-03 22:15 +0100 |
| Message-ID | <1mdc0d8.1vu8k8uw88oqgN%clkaufmann@gmx.ch> |
| In reply to | #2466 |
Helpful Harry <HelpfulHarry@BusyWorking.com> wrote: > If the GetAsDate function doesn't work, you'll have to do the > conversion quasi-manually within the script by parsing the text-date > using the "/" character as the delimiter for each part. I suggest converting the date to its number format when defining the script parameter: GetAsNumber ( YourDateField ) -- Christoph Kaufmann http://clk.ch
[toc] | [prev] | [next] | [standalone]
| From | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| Date | 2015-11-03 20:23 -0800 |
| Message-ID | <1mdbv1y.yhiv3h1amyb43N%csampson@inetworld.net> |
| In reply to | #2467 |
Christoph Kaufmann <clkaufmann@gmx.ch> wrote:
> Helpful Harry <HelpfulHarry@BusyWorking.com> wrote:
>
> > If the GetAsDate function doesn't work, you'll have to do the
> > conversion quasi-manually within the script by parsing the text-date
> > using the "/" character as the delimiter for each part.
>
> I suggest converting the date to its number format when defining the
> script parameter:
>
> GetAsNumber ( YourDateField )
I don't follow here. As I read the description of GetAsNumber,
GetAsNumber ("1/2/2016")
would return the number value 122016. Then, if that value is used as a
script parameter, it would be implicitly converted to text ("122016").
Then what should I do?
Charlie
--
Nobody in this country got rich on his own. You built a factory--good.
But you moved your goods on roads we all paid for. You hired workers we
all paid to educate. So keep a big hunk of the money from your factory.
But take a hunk and pay it forward. Elizabeth Warren (paraphrased)
[toc] | [prev] | [next] | [standalone]
| From | Helpful Harry <HelpfulHarry@BusyWorking.com> |
|---|---|
| Date | 2015-11-04 18:37 +1300 |
| Message-ID | <041120151837053144%HelpfulHarry@BusyWorking.com> |
| In reply to | #2469 |
In article <1mdbv1y.yhiv3h1amyb43N%csampson@inetworld.net>, Charles H.
Sampson <csampson@inetworld.net> wrote:
> Christoph Kaufmann <clkaufmann@gmx.ch> wrote:
> > Helpful Harry <HelpfulHarry@BusyWorking.com> wrote:
> >
> > > If the GetAsDate function doesn't work, you'll have to do the
> > > conversion quasi-manually within the script by parsing the text-date
> > > using the "/" character as the delimiter for each part.
> >
> > I suggest converting the date to its number format when defining the
> > script parameter:
> >
> > GetAsNumber ( YourDateField )
>
> I don't follow here. As I read the description of GetAsNumber,
>
> GetAsNumber ("1/2/2016")
>
> would return the number value 122016. Then, if that value is used as a
> script parameter, it would be implicitly converted to text ("122016").
> Then what should I do?
Working with dates and text dates can cause peculiar things to happen.
I'd just use the "/" character as the delimiter and parse out the
various parts of the text date. That way you know you've got what you
should have, rather than what automated functions *think* you should
have ... of course the data entry of the text date does have to be very
strict (always a "/", so no dates entered as "7.3.2015").
The Day* is everything up to, but not including, the first "/".
i.e.
TextDate_Day = Left(TDate; Position(TDate; "/"; 1; 1) - 1)
The Month* is the characters between the first "/" and the second "/"
(start after the first "/" and take the number of characters that is
all the characters minus everything up to and including the first "/"
and minus the five characters for the second "/" and four digit year).
i.e.
TextDate_Month = Middle(TDate; Position(TDate; "/"; 1; 1) + 1;
Length(TDate) - Position(TDate; "/"; 1; 1) - 5))
The Year is simply the last four digits (assuming the year is always
entered as four digits).
i.e.
TextDate_Year = Right(TDate; 4)
* You will need to swap the calculations for Day and Month if
you're using backwards American dates (MM/DD/YYYY).
To make it more efficient you could store the position of the first "/"
(Position(TDate; "/"; 1; 1)) in a variable so it is only calculated
once instead of three times.
Helpful Harry :o)
[toc] | [prev] | [next] | [standalone]
| From | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| Date | 2015-11-03 18:58 -0800 |
| Message-ID | <1mdbr35.1kl36bc180p4ctN%csampson@inetworld.net> |
| In reply to | #2465 |
Christoph Kaufmann <clkaufmann@gmx.ch> wrote: > Charles H. Sampson <csampson@inetworld.net> wrote: > > > Set Variable [$TDate; Value:Get(ScriptParameter)] > > Try GetAsDate ( Get ( ScriptParameter ) ) Just an interim report. I haven't exhaused all ideas yet. This didn't work. Based on the behavior of the script and the custom dialog outputs, nothing has changed. Those custom dialogs are reporting that the pairs of day, month, and year values are what I want them to be. Furthermore, there seems to be some sort of implicit type conversion going on. When I compared a text day to a numeric day, there were no complaints. I just got the usual results. And I tried converting the TDay, TMonth, and TYear values to numbers with no obvious change in results. Charlie -- Nobody in this country got rich on his own. You built a factory--good. But you moved your goods on roads we all paid for. You hired workers we all paid to educate. So keep a big hunk of the money from your factory. But take a hunk and pay it forward. Elizabeth Warren (paraphrased)
[toc] | [prev] | [next] | [standalone]
| From | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| Date | 2015-11-04 01:23 -0800 |
| Subject | Re: Problem With Dates in a Script (Solved) |
| Message-ID | <1mdc8o4.3tjp5hiyhdzqN%csampson@inetworld.net> |
| In reply to | #2464 |
Charles H. Sampson <csampson@inetworld.net> wrote: > I'm having trouble with a script that I have to manipulate dates in. > This is for FileMaker Pro 8.0v3 running on a G5 with OS X 10.5.8. > > I have to calculated a date based on two other dates. One of those other > dates in in text format. I'll call it TDate. It comes to the script as a > parameter and is obtained with the script step > > Set Variable [$TDate; Value:Get(ScriptParameter)] > > The other of those dates is from a global field in the database and is > presumably in FileMaker's internal format for a date. I'll call it > DDate. It is always referred to as > > Global Data::DDate > > but for simplicity in the following I'll just call it DDate. > > I use the Month, Day, and Year functions to obtain $TMonth, $TDay, > $TYear, etc. > > Here's the problem. I have the following if-statement: > > iI [$DYear < $TYear] > <do stuff 1> > Else if [$DMonth < $TMonth] > <do stuff 2> > Else > <do stuff 3> > End If > > (DDate will always be be less than TDate,) > > When I execute this script with DDate = 11/2/2014 and TDate = 1/2/2015, > it's <do stuff 3> that gets executed rather than <do stuff 1>. I have > custom dialogs immediately before and in each arm of the if-statement > that verify that the values are all what they should be. > > Any ideas? I suspect that it is something having to do with implicit > type conversions (between number and text) or an invisible character in > TDate. Or it's something else entirely and I'm not able to see it > because of that peculiar blindness that strikes coders from time to > time. > Problem solved. In the actual code, I had embedded spaces in the names of script variables. In the if-statement (above) the actual name used for TYear had two consecutive spaces. This didn't match the name with one space and some value was used, probably zero. The most user-unfriendly language feature I've ever seen compounded by a grotesque run-time feature. I've removed all embedded spaces in the names of script variables for this script. As time permits, I'm going to do the same in all other scripts, which will require retesting them. (This is low priority, obviously. The other scripts have been working as designed for a long time.) I apologize for wasting everybody's time. It won't be a complete waste of time if you consider my experience to be a cautionary tale. Charlie -- Nobody in this country got rich on his own. You built a factory--good. But you moved your goods on roads we all paid for. You hired workers we all paid to educate. So keep a big hunk of the money from your factory. But take a hunk and pay it forward. Elizabeth Warren (paraphrased)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.databases.filemaker
csiph-web