MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - How can I print the actual date ?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How can I print the actual date ?

 Post Reply Post Reply
Author
Message
JulioFilho View Drop Down
Contributor
Contributor
Avatar

Joined: 31.Jul.2013
Location: The Hague
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote JulioFilho Quote  Post ReplyReply Direct Link To This Post Topic: How can I print the actual date ?
    Posted: 11.Mar.2014 at 14:09
Hi guys,

I want to include a comment line in my code with the date and time of the generation.  How can I do that?

Thanks in advance,

Julio
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 641
Answer Answer
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 08.Apr.2019 at 12:21
In 5.5 and later, the code can be simpler (and significantly faster) with external...read:
 
external 'echo %date% %time%' read

This will be in your current locale format. 
For other date formats, see https://stackoverflow.com/a/19799236/1166064.
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 641
Post Options Post Options   Thanks (1) Thanks(1)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 11.Mar.2014 at 15:03
Date and time calculation and formatting is something we've deliberately left out of MERL, so you can just use whatever date and time library or OS function you're already familiar with. E.g. to grab the current date and time from DOS into a variable in MERL:
 
$dateTimeFile = 'datetime.txt'
external 'cmd /x /c echo %date% %time% >' $dateTimeFile executeBlocking
$dateTime = __(filename $dateTimeFile read)
 
There are probably good reasons in your case why you want to do this. In general, I wouldn't recommend including timestamps in source code - it means that every generation gives a different result, even though the real source, the model, hasn't changed. It also changes what the compiler sees as the source, so it will have to recompile every file every time; if you don't add the timestamp, MetaEdit+ automatically notices when the generated file is the same as what is already on disk, and doesn't overwrite it, which allows most compilers to avoid recompiling that file.
Back to Top
JulioFilho View Drop Down
Contributor
Contributor
Avatar

Joined: 31.Jul.2013
Location: The Hague
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote JulioFilho Quote  Post ReplyReply Direct Link To This Post Posted: 13.Mar.2014 at 12:11
Many thanks for the quick answer.

Well, I am doing that for documentation purposes in a file that does not affect compiler or things in the sort.  I do need that because I want to keep track of when the code (documentation) was generated.

Though I do not agree that it is not desirable to have that in MERL, I think your answer will do the trick for the moment.

Thanks again,

Julio


Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 641
Answer Answer
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post Posted: 08.Apr.2019 at 12:21
In 5.5 and later, the code can be simpler (and significantly faster) with external...read:
 
external 'echo %date% %time%' read

This will be in your current locale format. 
For other date formats, see https://stackoverflow.com/a/19799236/1166064.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.063 seconds.