Hello,
Can someone please give me some guidance on ordering dates. I want to display a list of dates in a list view control - the dates come out of a database. I want to be able to order the dates and I'm not sure how to go about doing this, can someone please give me some ideas?
Also, I've tried looking through the API and all the date functions seem to be about getting dates and altering their format as opposed to ordering them.
Thanks all,
~Adam
Posted on 2002-09-15 07:25:43 by adamjjackson
You can choose a starting date as day one, all other dates after that day will then be converted to an offset from that day. then all you have to do is order the numbers to get the dates in order.

eg the Julian number for a date is calculated using january 1 4713 BC as day one.

jday struct
day byte ? ;0=sunday...6=saturday
month byte ? ;0=january...11=December
year dword ?;1999,2000 etc
julianday dword ? ;julian day
jday ends

now once youve converted the day/month/year format to a julian day number you can sort them by this number.
you'l use the day and month values to select the correct string to display....

well thats one method...
Posted on 2002-09-15 16:10:05 by MArtial_Code
Okay, I was thinking of converting the date to yyyymmdd format and then ordering them from there. I'll give that a go anyway.
Thanks.
Posted on 2002-09-16 04:19:55 by adamjjackson
yeah that would work too and is simpler...
Posted on 2002-09-16 05:24:59 by MArtial_Code
I'm stuck, please can someone help.
The format of the date string I want to alter is "yyyy-mm-dd hh:mm:ss", e.g. "2002-09-16 17:04:57".
I want to change this to "yyyymmdd", e.g. "20020916". How do I do this? I don't know how to go about removing the hyphens, I understand how to cut the string down but...
Thanks,
~Adam
Posted on 2002-09-16 11:02:09 by adamjjackson
Come on, parsing that is easy doing. Take a look at these threads and you might get an idea how to parse it:

http://www.asmcommunity.net/board/index.php?topic=3690&highlight=string+parsing
http://www.asmcommunity.net/board/index.php?topic=5272&highlight=string+parsing
Posted on 2002-09-16 11:07:50 by bazik
Lol, for you maybe - I'm kinda new (still), just trying to learn as I go along. I'll have a look at those threads, thanks a lot.
~Adam
Posted on 2002-09-16 11:17:03 by adamjjackson
okay you want to convert yyyy-mm-dd __:__:__ to yyyymmdd?

.data
string_1 db "2002-09-16 17:04:57",0
string_2 db "________",0

.code
lea esi, string_1
lea edi, string_2
mov eax, dword ptr
mov dword ptr , eax
mov ax, word ptr
mov word ptr , ax
mov ax, word ptr
mov word ptr , ax

invoke MessageBox,0,addr string_1, addr string_2,0



i hope i didn't calculated wrongly... if thats the case please grab your
debugger and correct the offsets
Posted on 2002-09-16 11:44:05 by mob
Hi,
Yup, that's what I want to do, I'll give it a go later. I was missing the keyword 'parsing' when I searched the board. I really need to just crack on and try this stuff myself! It all looks so complicated though! :stupid:
Posted on 2002-09-16 11:50:29 by adamjjackson
uh and don't forget to save edi and esi in your windowproc



WndProc PROC USES EDI ESI hWnd : DWORD, uMSG : DWORD, wParam : DWORD, lParam : DWORD


esi, edi and ebx MUST be saved to stack if you use them in callback functions!
or just use other registers... your choice
Posted on 2002-09-16 11:51:45 by mob
Yeah, I understand they have to be saved and how to do that. What advantage do those registers have? I mean, it must use up resources having to save them, so are they quicker at their job than other registers which don't have to be preserved?
Thanks.
Posted on 2002-09-16 12:00:37 by adamjjackson
no iT doesn't eat up memory... only the stack grows four bytes... but after
the callback is ready to return it balances the stack automaticly (when you're
using the "USES" command)...

edi and esi are segment registisers and yes, they have an huge advatage
against other registers, they're not touched by windows apis in any way...
after you use a regular windows api you can not rely on eax,ecx,edx anymore
but you can on edi, esi and ebx (which is NOT a segment register btw.)

i doubt that segment registers are somewhat slower than the general purpose
ones but i might be wrong... i never took that into account when coding... maybe
someone knows this better and i'm learning something new :)
Posted on 2002-09-16 12:08:32 by mob
(ESI and EDI are not segment registers.)

If you don't use the registers, you don't need to save them.
This register convention is primarily for the convenience of compilers. You need to study compiler construction to get a feel for why this convention might be desirable.

The convention is also useful for direct assembly coding (our kind of coding).
The registers which are not guaranteed to be preserved are best used in instruction sequences that don't call APIs.
The registers which are preserved are best used in sequences which include API calls.

Example:
    mov esi,offset String1   ; ESI will be preserved by API call

mov edi,offset String2 ; EDI will be preserved by API call
mov ebx,nCount ; EBX will be preserved by API call
loop1:
mov al,[esi] ; copy character
mov [edi],al
mov ecx,multValue ; we won't use this ECX value after API
mul ecx ; MUL alters EAX and EDX, we won't use these values after API
mov multValue,edx
invoke MessageBox,hWnd,addr Caption1,addr Text1,MB_OK
inc esi
inc edi
dec ebx
jnz loop1
Posted on 2002-09-16 21:22:37 by tenkey
pointer registers... i confounded those two descriptions
Posted on 2002-09-17 03:23:17 by mob