Sorting

H

Harmannus

Hallo,

I have a query with the next code:

Sorting: Year(Date()) & Month([dateofbirth]) & Day([dateofbirth])

How can a sort ascending on this field? The results 2004101, 200411 etc. do
not get sorted correctly. The outcome should be 20041001, 20040101 etc. Any
suggestion on how to correct his.

Tried adding: format(Month([dateofbirth]);"mm") but that doesn't work...

Or can i sort on the dateofbirth related to the current year through another
trick :) with code added to it?

Thanx in advance for any tips.

Regards,

Harmannus
 
J

John Vinson

Hallo,

I have a query with the next code:

Sorting: Year(Date()) & Month([dateofbirth]) & Day([dateofbirth])

This builds a text string and loses the leading zeros... hence
incorrect sorting as you see!
Or can i sort on the dateofbirth related to the current year through another
trick :) with code added to it?

Try

Sorting: DateSerial(Year(Date()), Month([dateofbirth]),
Day([dateofbirth]))

This will give you a Date/Time value which will sort correctly; and
you can use criteria such as

BETWEEN Date() AND Date() + 7

to find the birthdays coming up in the next week.
 
H

Harmannus

Hallo,

Thanx for the reply.

Great help!

Regards,

Harmannus

John Vinson said:
Hallo,

I have a query with the next code:

Sorting: Year(Date()) & Month([dateofbirth]) & Day([dateofbirth])

This builds a text string and loses the leading zeros... hence
incorrect sorting as you see!
Or can i sort on the dateofbirth related to the current year through another
trick :) with code added to it?

Try

Sorting: DateSerial(Year(Date()), Month([dateofbirth]),
Day([dateofbirth]))

This will give you a Date/Time value which will sort correctly; and
you can use criteria such as

BETWEEN Date() AND Date() + 7

to find the birthdays coming up in the next week.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top