need help to output dates in format YYMMDD to file

nnCron and nnCron LITE discussion

need help to output dates in format YYMMDD to file

Postby LuckMan212 » Sat, 17 Sep 2005, 01:13

hello,

I need to write a task that outputs the current date, as well as the 3 previous dates, each on one line, to a text file. It should be in YYMMDD format, like this:
Code: Select all
050913
050914
050915
050916

I have not had very much luck making this task. I have tried the following code but it is not complete and does not run, resulting in an error:
Code: Select all
#( aaa_test_file_write
CREATE myDatesFile 256 ALLOT S" dates.txt" myDatesFile ZPLACE
VARIABLE myStr1
VARIABLE myStr2
VARIABLE myStr3
VARIABLE myStr4
Action:
   CUR-DATE DATE>S myStr1 !
   CUR-DATE -1 DAY+ DATE>S myStr2 !
   CUR-DATE -2 DAY+ DATE>S myStr3 !
   CUR-DATE -3 DAY+ DATE>S myStr4 !

   FILE-WRITE: "%myDatesFile ASCIIZ>%" "%myStr1 @% %crlf% %myStr2 @% %crlf% %myStr3 @% %crlf% %myStr4 @%"
)#

Can you please help me to create this task?
Thank you!! :wink:
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Nicholas_Nemtsev » Sat, 17 Sep 2005, 09:34

Code: Select all
...
: YYMMDD ( y m d -- a u)
   <# S>D # # 2DROP S>D # # 2DROP S>D # # #> ;
: CUR-YMD+ ( n -- y m d) >R Year@ Mon@ Day@ R> DAY+ ;
...
Action:
    0 CUR-YMD+ YYMMDD S>ZALLOC myStr1 !
   -1 CUR-YMD+ YYMMDD S>ZALLOC myStr2 !
   -2 CUR-YMD+ YYMMDD S>ZALLOC myStr3 !
   -3 CUR-YMD+ YYMMDD S>ZALLOC myStr4 !

FILE-WRITE: "%myDatesFile ASCIIZ>%" "%myStr1 @AZ%%crlf%%myStr2 @AZ%%crlf%%myStr3 @AZ%%crlf%%myStr4 @AZ%"
Nicholas Nemtsev
User avatar
Nicholas_Nemtsev
Site Admin
 
Posts: 857
Joined: Thu, 01 Jul 2004, 22:25
Location: Псков

Postby LuckMan212 » Sat, 17 Sep 2005, 10:01

thank you Nicholas!! :D :D
you are brilliant as usual

it works perfectly...

now If only I was smart enough to write this on my own... <sigh> :cry:
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby LuckMan212 » Sat, 17 Sep 2005, 10:03

oh 1 more thing can I ask why:
Code: Select all
CREATE myDatesFile 256 ALLOT S" %WINDIR%\dates.txt" myDatesFile ZPLACE

this doesn't work? do postfix notation not allow for use of system variables?

when I use this code I get a folder named %WINDIR% in my nnCron folder instead of the desired result... strange!
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Nicholas_Nemtsev » Sat, 17 Sep 2005, 10:26

Code: Select all
CREATE myDatesFile 256 ALLOT S" %WINDIR%\dates.txt" EVAL-SUBST myDatesFile ZPLACE
Nicholas Nemtsev
User avatar
Nicholas_Nemtsev
Site Admin
 
Posts: 857
Joined: Thu, 01 Jul 2004, 22:25
Location: Псков

Postby LuckMan212 » Sat, 17 Sep 2005, 10:30

brilliant!! :idea:
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Sat, 17 Sep 2005, 11:05

2 LuckMan212:

Take a look in the docs for further explanation of the 'postfix notation - predefined variables' issue: http://www.nncron.ru/help/EN/add_info/f ... m#evaluate
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Mon, 24 Jul 2006, 01:40

okay, recently the website where I download my files has changed the date formatting for their files, and now I need to format date as MMDDYY :(

I modified the above task so it will work correctly, but I think it is a very inefficient method I used:
Code: Select all
#( test_dates_MMDDYY
NoActive
CREATE date_str_tmp 256 ALLOT
CREATE date_str1 256 ALLOT
CREATE date_str2 256 ALLOT
CREATE date_str3 256 ALLOT
CREATE date_str4 256 ALLOT
: YYMMDD ( y m d -- a u)
   <# S>D # # 2DROP S>D # # 2DROP S>D # # #> ;
: CUR-YMD+ ( n -- y m d) >R Year@ Mon@ Day@ R> DAY+ ;
Action:
   0 CUR-YMD+ YYMMDD date_str_tmp PLACE
   date_str_tmp COUNT 2 /STRING date_str1 PLACE
   date_str_tmp COUNT 4 - 0 MAX date_str1 +PLACE
   -1 CUR-YMD+ YYMMDD date_str_tmp PLACE
   date_str_tmp COUNT 2 /STRING date_str2 PLACE
   date_str_tmp COUNT 4 - 0 MAX date_str2 +PLACE
   -2 CUR-YMD+ YYMMDD date_str_tmp PLACE
   date_str_tmp COUNT 2 /STRING date_str3 PLACE
   date_str_tmp COUNT 4 - 0 MAX date_str3 +PLACE
   -3 CUR-YMD+ YYMMDD date_str_tmp PLACE
   date_str_tmp COUNT 2 /STRING date_str4 PLACE
   date_str_tmp COUNT 4 - 0 MAX date_str4 +PLACE
   FILE-WRITE: "%WINDIR%\Temp\dates.txt" "%date_str1 COUNT%%crlf%%date_str2 COUNT%%crlf%%date_str3 COUNT%%crlf%%date_str4 COUNT%"
)#

Can you please help me to make this repetitive section into a custom Sp-Forth word?
Code: Select all
   date_str_tmp COUNT 2 /STRING date_str1 PLACE
   date_str_tmp COUNT 4 - 0 MAX date_str1 +PLACE
I think this can be done, but I do not know how. Or as an alternative-- how can I perform "date math" e.g. CUR-DATE +2 etc but output directly to MMDDYY format? is it possible?

thank you very much as always for your guidance in my time of need!! :D
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Nicholas_Nemtsev » Thu, 27 Jul 2006, 15:16

Code: Select all
#( test_dates_MMDDYY
NoActive
CREATE date_str_tmp 256 ALLOT
CREATE date_str1 256 ALLOT
CREATE date_str2 256 ALLOT
CREATE date_str3 256 ALLOT
CREATE date_str4 256 ALLOT
: YYMMDD ( y m d -- a u)
   <# S>D # # 2DROP S>D # # 2DROP S>D # # #> ;
: CUR-YMD+ ( n -- y m d) >R Year@ Mon@ Day@ R> DAY+ ;
: AABBBB2BBBBAA ( a u where -- )
   >R
   2DUP 2 /STRING R@ PLACE
   4 - 0 MAX R> +PLACE ;
Action:
   0 CUR-YMD+ YYMMDD date_str1 AABBBB2BBBBAA
   -1 CUR-YMD+ YYMMDD date_str2 AABBBB2BBBBAA
   -2 CUR-YMD+ YYMMDD date_str3 AABBBB2BBBBAA
   -3 CUR-YMD+ YYMMDD date_str4 AABBBB2BBBBAA
   FILE-WRITE: "%WINDIR%\Temp\dates.txt" "%date_str1 COUNT%%crlf%%date_str2 COUNT%%crlf%%date_str3 COUNT%%crlf%%date_str4 COUNT%"
)#
Nicholas Nemtsev
User avatar
Nicholas_Nemtsev
Site Admin
 
Posts: 857
Joined: Thu, 01 Jul 2004, 22:25
Location: Псков

Postby LuckMan212 » Fri, 28 Jul 2006, 00:05

:D :shock: :lol: :o
Nicholas, thank you so much, as always you are brilliant with your solutions
very much appreciated
Luke
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 3 guests