News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Function to know how many days have passed this year

Started by clamicun, March 21, 2016, 05:56:58 AM

Previous topic - Next topic

clamicun

There are lots of asm examples  in the datetime folder.
Which one gives me the desired result?
DayOfYear ???  The result is strange.

jj2007

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Inkey Str$("%i days since 1st of January\n", Age(TimeSF("01.01."), d))
EndOfCode


Output:
79 days since 1st of January

clamicun

Thank you JJ,
79 days today.
But that is not going to help me much.
My prog reads "Dates" from a database, which are all different.
So I have to give year, month and day to the function (Macro).
How do you do that?

jj2007

TimeSF() expects a string in the format dd.mm.yy - in the example above, 01 january (and the macro assumes "current year" if no year is supplied).

What is the format of your database? Can you post an example?

clamicun

Format ?
It returns  a string, which contains year,month,day  "2014-04-25"
Then the three values get changed into ints.

jj2007

Quote from: clamicun on March 21, 2016, 09:39:46 AM
It returns  a string, which contains year,month,day  "2014-04-25"

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Let esi="2014-04-25"
  Let esi=Mid$(esi, 9, 2)+"."+Mid$(esi,6, 2)+"."+Left$(esi, 4)
  Inkey Str$("%i days since ", Age(TimeSF(esi), d)), esi
EndOfCode


Output:
696 days since 25.04.2014

clamicun

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Let esi="2014-04-25"
  Let esi=Mid$(esi, 9, 2)+"."+Mid$(esi,6, 2)+"."+Left$(esi, 4)
  Inkey Str$("%i days since ", Age(TimeSF(esi), d)), esi
EndOfCode
Output:
696 days since 25.04.2014
--------------------------
yes.. 696 day since...
--------------------------

But - as always with MasmBasic - where is the result ?
(I never use console built)
It is not esi, edi,eax, not ...

It is %i  ???
As I often said...I do not understand your Macros.
Where or what  is it ?

And I can't use it anyway in my project.
"Let esi="2014-04-25"
Let esi=Mid$(esi, 9, 2)+"."+Mid$(esi,6, 2)+"."+Left$(esi, 4)"

I have my own proc which corresponds to php's explode.

mov esi,offset downloaded_data  ; (2014-04-25) 
explode offset year,'-'   
explode offset month,'-'   
explode offset day,0   
(Then - if need - I convert them into ints)
------------
So I think, I should try..
DayOfYear PROC pdt:PTR DATETIME
DaysInMonth PROC pdt:PTR DATETIME

There I do not understand  "pdt:PTR DATETIME"
That is...what do I invoke ...?
Should be year,month,day

INVOKE DayOfYear,offset  systemTime ; from  (INVOKE GetLocalTime,offset systemTime) - does not function

I'll get it tomorrow or the day after, but If you are not pi..d  because of not wanting to use your "LiveProject MsBs"   give me a hint please.
PS.
Don't forget to tell me the "whereabout" of %i



nidud

#7
deleted

jj2007

Quote from: clamicun on March 21, 2016, 12:33:27 PM
As I often said...I do not understand your Macros
...
Don't forget to tell me the "whereabout" of %i

Sorry for that (btw, what does explode offset year,'-' do?). Here is a version closer to your needs:

include \masm32\MasmBasic\MasmBasic.inc      ; download
.data
downloaded_data  db "2014-04-25", 0
  Init
  Let esi=offset downloaded_data ; (2014-04-25)
  Let esi=Mid$(esi, 9, 2)+"."+Mid$(esi,6, 2)+"."+Left$(esi, 4)      ; convert to 25.04.2014
  Let esi=Str$("%i days since ", Age(TimeSF(esi), d))+esi
  MsgBox 0, esi, "The result:", MB_OK
EndOfCode


As to the %i, google for printf format integer

Note that of course, you could declare...
.data
MyResult dd ?

... and then replace all occurrences of esi with MyResult.

Re GetLocalTime etc: If you want to roll your own, it's all in \Masm32\MasmBasic\MasmBasic.inc, ca. lines 4415...4510

clamicun

;esi must be set on offset string toprocess e.g. 2016-03-21
;arg1 offset string to create   ;eg. year db 4 dup(?),0
;arg2 delimiter     '-'

;mov esi,offset toprocess
;explode offset year,'-'
;===

explode MACRO arg1,arg2   
LOCAL thislabel                     
LOCAL thisoutlabel

push eax
mov edi,arg1

thislabel:
mov al,[esi]
cmp al,arg2
je thislabelout
inc esi
mov [edi],al
inc edi
jmp thislabel

thislabelout:
inc esi

pop eax
ENDM

clamicun


clamicun


clamicun

nidud,
actually it gives me 20some syntaxerrors !!
Did you ever test it ?

nidud

#13
deleted

jj2007

GetDays   ( 1900, 01, 01 ): 42448

The build is a bit non-standard*), but it works :t

How do you deal with local time vs UTC?

Btw your printf "\n" puts out a LF only. In contrast, Masm32 printf emits CRCRLF 8)

include \masm32\include\masm32rt.inc

.code
start:
  xor ebx, ebx
  .Repeat
printf("Test %d \n", ebx)
inc ebx
  .Until ebx>=3
  exit

end start


*)
P.S.: *.asc attached; hit F6 to build in RichMasm, \Masm32\bin\AsmC needed