Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Building a Date in Access 2003

Author  Topic 

gkemp
Starting Member

2 Posts

Posted - 2008-03-03 : 23:43:29
I am trying to build a date for the current year given I have the month and day in Access 2003

I noticed in the sql Server 2000 forum the following was suggested as a solution

dateadd(day, @day - 1, dateadd(month, @month - 1, dateadd(year, @year-1900, 0)))

I have translated this to

DateAdd('d',[Day],DateAdd('m',[Month],DateAdd('yyyy',DatePart('yyyy',Date())-1900,0)))

but seem to be getting some funny results. NOTE: I have tried subtracting 1 from Day and Month.

Results are as follows:




Day Month Results Should be
3 3 4/2/2008 (3/3/2008)
2 4 5/2/2008 (4/2/2008)
5 4 5/5/2008 (4/5/2008)
11 4 5/11/2008 (4/11/2008)
12 4 5/12/2008 (4/12/2008)

Can anyone suggest what I'm doing wrong?

I'm new to all this Access / sql stuff so any help you can give would be great.

Geoff

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-04 : 01:31:58
Why not use DATESERIAL(yyyy, mm, dd)?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

gkemp
Starting Member

2 Posts

Posted - 2008-03-04 : 09:06:34
quote:
Originally posted by Peso

Why not use DATESERIAL(yyyy, mm, dd)?



E 12°55'05.25"
N 56°04'39.16"




As I said I'm new to Access/SQL and therefore did'nt know about DateSerial. I do now and had I known before it would have saved me hours of messing around. Many thanks for your help it works a treat.

Geoff
Go to Top of Page
   

- Advertisement -