change Date format in exported file

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

change Date format in exported file

Postby bobm » Tue Aug 11, 2020 9:49 pm

I'm exporting some patient data and looking to set the date format as mmddyyyy
Postgres stores the data as yyyy-dd-mm 00:00:00:0
I'm using a straight ds export to a comma delimited txt file

Code: Select all
      patients.loadAllRecords();
      var ds = databaseManager.convertToDataSet(patients,['patient_id','last_name','first_name','address','address2','city','state','zipcode','dob'']);
      var str=ds.getAsText(',','\n',"",true);
      
      scopes.file.writeTXTFile(patientsFromCloud,str);


Thank you,
Bob
Bob Mezzadri
EyeCOR By Nteon
bobm
 
Posts: 81
Joined: Thu Dec 29, 2011 8:24 pm

Re: change Date format in exported file

Postby ROCLASI » Tue Aug 11, 2020 10:18 pm

Hi Bob,

You can loop through the DataSet and format (utils.dateFormat()) the date while putting the result in an array.
But it's probably more efficient to simply use a SQL query and format the date in there like this (assuming the table is named 'patients' and all records are saved to the database):
Code: Select all
// replace 'connectionName' with the proper value
var ds = databaseManager.getDataSetByQuery("connectionName",
    "SELECT patient_id, last_name, first_name, address, address2, city, state, zipcode, to_char(dob, 'MMDDYYYY') AS dob FROM patients",
    null, -1);
if ( ds.getException()) {
    throw ds.getException();
}
// get the result and write it straight to the file
scopes.file.writeTXTFile(patientsFromCloud, ds.getAsText(', ','\n', "", true));

See https://www.postgresql.org/docs/current ... tting.html for all the formatting options.

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: change Date format in exported file

Postby bobm » Wed Aug 12, 2020 3:22 pm

Thank you again for you help on this. needed to set a couple args but worked great!
Bob Mezzadri
EyeCOR By Nteon
bobm
 
Posts: 81
Joined: Thu Dec 29, 2011 8:24 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests

cron