Source language: Translate to:

Create Text File With Date/Time Stamp As Its Name

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Create Text File With Date/Time Stamp As Its Name

Postby Ken1000 » Sat Apr 07, 2007 6:48 am

Hi. I'm sure there's a simple answer to this, but I cannot seem
to come up with it.

I want to write a text file that has within its name the current date/time
in this format Year-Month-Day-Hour-Minute-Seconds. For example, if
the text file created was named 20070403175906.txt, the name would
signify that it was created on 04-03-2007 17:59:06

Year = 2007 Month = 03 Day = 17
Hour = 17 Minute = 59 Second = 06

How do I join together the global variables Year, MonthNum, DayNum,
Hour, Minute, and Second into a single variable that will be used in
the data file name in a FileWrite statement? That is, the text file's name
would be the current date and time (as mentioned above).

Could you please share some simple sample code that does this?

Thank you very much.

Ken
Ken1000
 
Posts: 8
Joined: Sat Apr 23, 2005 10:46 pm

Postby Wrangler » Sat Apr 07, 2007 7:08 am

FileWrite "[year][month][day][hour][minute][seconds].txt" "" ""

or

setvar "[filename]" "[year][month][day][hour][minute][seconds].txt"
FileWrite "[filename]" "" ""
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby Gaev » Sat Apr 07, 2007 7:29 am

I pulled this code from one of my applications that needed the same functionality ... since some of the Global Variables do not include leading Zero's when numbers are less than 10, this is something generic you can use ...
Code: Select all
:FormatTimeStamp
If "[MonthNum]" "<" "10"
    SetVar "[gkMonthNum]" "!0[MonthNum]"
Else
    SetVar "[gkMonthNum]" "![MonthNum]"
EndIf
If "[DayNum]" "<" "10"
    SetVar "[gkDayNum]" "!0[DayNum]"
Else
    SetVar "[gkDayNum]" "![DayNum]"
EndIf
If "[Hour]" "<" "10"
    SetVar "[gkHour]" "!0[Hour]"
Else
    SetVar "[gkHour]" "![Hour]"
EndIf
SetVar "[gkTimeStamp]" "![Year][gkMonthNum][gkDayNum]_[gkHour][Minute][Second]"
Return

a) You can alter the second last line of code if you don't want the underscore separator between date and time ... or if you want additional separators.

b) Then use [gkTimeStamp] in any NeoBook command you like e.g.
Code: Select all
FileWrite "abc_[gkTimeStamp].txt" "All" "[blahblahblah]"

.. or just display [gkTimeStamp] in a Text object etc. etc.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Ken1000 » Wed Apr 11, 2007 5:53 pm

Sorry I did not reply sooner. I truly thank you both for your help.

Ken
Ken1000
 
Posts: 8
Joined: Sat Apr 23, 2005 10:46 pm


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest