Jump to content

This topic is 8453 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I want to export a date field to a CSV file in the format YYYYMMDD, i.e., today's date is expressed 20020115. I can't figure out how to set an option in FM to do this. Would appreciate any help, thanks.

Posted

If you want the date to export to three different fields, i.e. Year, Month, Day, create calc fields for Year(Date) etc.

For a single field, YYYYMMDD, create a calc field that has all three strung together. To be certain that you end up with eight digits, use an "if" statement to check if the month and day are less than 10, and adding a "0" if necessary.

Posted

That’s the right way, but I wouldn’t use an IF here – use the CASE statement instead. Always get into good habits early.

Calculating field=

Year(MDATE) &

Case(Month(MDATE) < 10,"0" & Month(MDATE), Month(MDATE)) &

Case(Day(MDATE) <10, "0" & Day(MDATE), Day(MDATE))

You can just copy this text into your calculation and replace MDATE with your date field. It works a treat and is faster than an IF. Try to avoid IF’s whenever you can. In the above calculation it doesn’t really make much difference, but in a long calculation it makes a big, big difference. The reason is as follows:

When a program meets an IF statement, it checks to see if it is met or not, regardless of YES or NO, it then carries on through the other clauses, so for example:

IF x = 20 then y = 50, IF x = 30 then y = 100, etc. etc. The program checks to see if x= 20 (Lets say it does) then sets y to 50, but then still checks again to see if x = 30, etc. etc. As you can imagine, if you have a lot of possible results for the IF statement, the computer spends a lot of time checking for useless information. The CASE statement however, will leave that particular case as soon as a Boolean “YES” is returned. This is why the case is much faster than an IF.

Not a lot of people know this – but it’s true!

Posted

Rigsby

Sorry, I can't follow on this:

to come back to your example, I would write it like this:

code:


if x = 20

set y to 50

else

if x = 30

set y to 100

end if

end if

So, if x is really 20, the "else-code" is ignored and no further tests will be done, isn't it? crazy.gif" border="0

How would you write this in case-statements?

Gerd

Posted

Jerry,

When you export there is an option to "Format output using current layout". You can change the date format of the original date field to YYYYMMDD, using leading zeroes for month and day. Switch to this layout just before you export.

Gerd,

Case() is really a shorthand for nested If()'s. While you can write this:

If(a,

This topic is 8453 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.