Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 69
  • Last Modified:

Csv files date

I want to collect the dates of each filename.  I am getting all the data of each filename except the dates.  The date can come from filenames like the building number.  The building in the filenames are being stored with the other data except the dates.  The filenames, for example, looks like this 100_2016-10-3_10-31.  The first three numbers are the building numbers, the date, and _10-31 is the time. How can I get the dates stored as well?
C--Users-campbme-Documents-CSV-file.docx
0
campbme
Asked:
campbme
  • 3
1 Solution
 
pcelbaCommented:
Dirty way:

You may simply update the following command in your code:

DO ImportFile WITH m.lcPath, laFiles[m.lnI, 1]

to

lcDateStr = CHRTRAN(STREXTRACT(laFiles[m.lnI, 1], '_', '_'), '-', ',')
DO ImportFile WITH m.lcPath, laFiles[m.lnI, 1], DATE(&lcDateStr))  && Remember you are sending the Date data type here

lcDateStr should be declared as LOCAL in the declaration part on top.

Cleaner way would be to parse the date from the file name without the & macro substitution, e.g.

*-- Four digits year is expected
lcDateStr = STREXTRACT(laFiles[m.lnI, 1], '_', '_')
ldFileDate = DATE(VAL(m.lcDateStr), VAL(SUBSTR(m.lcDateStr, 6)), VAL(SUBSTR(m.lcDateStr, AT('-', m.lcDateStr, 2)+1)))
DO ImportFile WITH m.lcPath, laFiles[m.lnI, 1], m.ldFileDate

Additional ways exist...
0
 
pcelbaCommented:
campbme, did you try this solution? It must work because I've tested in on my own data.

If you are not sure what to do then simply place  SET STEP ON  at the beginning of the code and it will open debugger where you can investigate values of your variables in each line and go through your code step by step.

Of course I can offer more help but you have to respond to the posts.
0
 
pcelbaCommented:
Unfortunately, the question author did not respond but I know my answer works well because it was tested in VFP9.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now