About EasyMorph Tutorials & Examples Web-help

How to add date & time to exported file name

I need to add the date and time to the same file name every time I run a project using the “Export into delimited text file” action.

I have succeeded in adding just the date to the filename with:

’G:\My Drive\Finance\MyFileName ’ & format(today(), ‘yyyy-MM-dd’) & '.csv’

as a parameter

the result is a file with the name: MyFileName 2019-10-15.csv

but when I change that parameter to:

’G:\My Drive\Finance\MyFileName ’ & format(now(), ‘yyyy-MM-dd HH:mm’) & '.csv’

I get “The given path’s format is not supported”

I need the file to be named:

MyFileName 2019-10-15 13:45.csv

Thanks for any help!

To the best of my knowledge a : (colon) is reserved and can’t be used in a windows file name, can you replace it with another character?

Yes - the colon was one problem.
The other was that you have to pass Now() into utctime() or localtime() like so:

'G:\My Drive\Finance\MyFileName ’ & format(utctime(now()), ‘yyyy-MM-dd HH mm’) & ‘.txt’

Thanks for the help

1 Like

Hi. I am having the same problem.
According to documentation: LocalTime(date_as_number) should be:


The : cannot be used.

The second problem is the time it generates

Here are 2 examples:
{ReportDate} = format(localtime(today()),“dd- MMM- yyyy_HHMMss”)
'AllFile ’ & {ReportDate} & ‘.xlsx’
Result: AllFile 08- Nov- 2019_101100.xlsx
(Time ran 8/11/2009 6:24am local time)

{ReportDate} = format(today(),“dd- MMM- yyyy_HHMMss”)

'AllFile ’ & {ReportDate} & ‘.xlsx’
Result = AllFile 08- Nov- 2019_001100.xlsx
(Time ran 8/11/2009 6:26am local time)
Just ran it again at 6:33 - file name stays - AllFile 08- Nov- 2019_001100.xlsx

I am running this on my local pc, but will move it over to Server

Thanks for your support on this.

Did you try

localtime(now())

1 Like

Thanks you Hendrik.
It solved my problem.

This means the documentation needs to be updated as today() does not give the expected results.

Many thanks

R

Hi @Rykie,

Both today() and now() functions return values in the local timezone. So there is no reason to additionally call the localtime() function. If you want to calculate a datetime value which will be the same in any timezone, you should use the utctime() function instead.

If you want to convert a value in the local time to a specific timezone, you’ll have to add offset of that timezone to the result of the utctime() function.

Also in the following expression:

format(today(),“dd- MMM- yyyy_HHMMss”)

you should specify HHmmss instead of HHMMss since MM is a format string component for a month.

Thanks, Andrew.

Here are my results:

I cannot get Today() to work.

UCT works with now(), but not with HH:mm; HHmm works

Thanks for your assistance.

Rykie

Hi @Rykie,

Everything looks good to me.

today() returns today’s date without time. So 09-Nov-2019_000000 is a correct result.

HH:mm doesn’t work since : character is not allowed in Windows filenames.

Or am I missing something?

1 Like

Hi Andrew

Thanks for your response and assistances
.
I thought today = date & time, which I now see is not - only date
now() gives you the date & time.

So I will use Now().

Converts a UTC date/time into a local date/time.
http://help.easymorph.com/doku.php?id=syntax:functions:localtime

Formula:
format(localtime(#2019-01-01), ‘yyyy-MM-dd HH:mm’)

You did indicate thet HH;mm is not correct - and I can confirm that I cannot get that part to work, so I changed it to HHmm

Could the documentation be updated please?

Thanks

Hi Rykie,

what would you suggest to change in the documentation?

To learn more about EasyMorph visit easymorph.com.