jburg1254 Posted January 16, 2002 Posted January 16, 2002 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.
danjacoby Posted January 16, 2002 Posted January 16, 2002 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.
Rigsby Posted January 16, 2002 Posted January 16, 2002 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!
Gerd Muller Posted January 16, 2002 Posted January 16, 2002 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? How would you write this in case-statements? Gerd
Thom Posted January 16, 2002 Posted January 16, 2002 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,
Gerd Muller Posted January 16, 2002 Posted January 16, 2002 Thom ...evident like a flash now!! Thanks Gerd
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now