Hi All, I am creating CSV file using suite script....
# suitescript
s
Hi All, I am creating CSV file using suite script. There is a date column of format mm/dd/yyyy. If the date is 11/03/2021, it is showing as 11/3/2021. I put the logic to add zero but it is not working. Is there any way to put the zero?
b
what does your code look like
s
thank you @battk var year = arrayValue[0].substring(0,4); var month = arrayValue[0].substring(4,6); month=('0'+month.toString()).slice(-2); var dt = arrayValue[0].substring(6,8); dt=('0'+dt.toString()).slice(-2); date = year+'/'+month+'/'+dt;
b
and what is arrayValue[0], and more importantly where does it come from
s
20211103
b
if it comes from a field or column in netsuite, then the script type matters as well
s
it comes from CSV file. I read the data from one CSV file and create one new CSV file
b
while ugly, that code doesn't look like it truncates the 0
have you tried logging the date variable
or looking at the csv file in a text editor
s
yes when i open csv file in a text editor it has zero
b
my guess is that someone is using excel
and their default date format is removing the 0
s
yes you are correct. when i manually change the column format to (yyyy/mm/dd), it has zero. And i don't think we can set column format via suitescript..right?
b
no, csv files are far too simple for that
s
ok, is there any other way?
b
csv has no specifications about how to interpret strings
thats the job of the software reading the csv
if you dont control that software, you need to change file formats
its a lot harder to generate excel files
s
Ok got it, thank you