Working with dates.. <..>

# Thread: Working with dates.. <..>

1. Senior Member
Join Date
Dec 1969
Posts
205

## Working with dates.. <..>

HI, <BR><BR>1. Can someon please explain to me what does the function<BR>dateSerial() what is its purpose and how does it work?<BR><BR>2. I found this fuction which is supposed to return the number of days in a month. It takes the month and year as its argument. For example if i call <BR><BR>noOfdays = getNumberofDays(february, 1998)<BR><BR>it should return 28<BR><BR>Here is the function...<BR><BR>Function GetDaysInMonth(iMonth, iYear)<BR>Dim dTemp<BR>dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))<BR>GetDaysInMonth = Day(dTemp)<BR>End Function<BR><BR>And here are my questions...<BR>1. Why is the function using the dateAdd function?<BR>2. Inside dateAdd why is it reducing the day (-1) instead of adding it?<BR>3.Just what exactly is the point of dateserial in this function..<BR><BR>Thanks

2. Member
Join Date
Dec 1969
Posts
63

## RE: Working with dates.. <..>

1. All DateSerial() does is take 3 arguments and makes it into a date subtype, <BR>Code: <BR>&#060;%= DateSerial(1943, 6, 26) %&#062; <BR>Output: <BR>6/26/43 <BR><BR>2. I rewrote your function:<BR><BR>&#060;%<BR> Function GetDays(Month, Year) <BR> Dim dTemp <BR> dTemp = DateAdd("d", -1, DateSerial(Year, Month + 1, 1)) <BR> GetDays = Day(dTemp) <BR> End Function <BR><BR> Response.Write GetDays(2, 2001)<BR>%&#062;<BR><BR>3. The reason it wasnt working before is because you were supposed to pass in the MONTH as a number, like instead of passing February you need to pass 2.<BR><BR>Hope that helps.

3. Senior Member
Join Date
Dec 1969
Posts
205

## RE: Working with dates.. <..>

Thanks for that.. what about dateadd().. whats going on there? I can see that its subtracting one month but i dont understand why.. and i also dont understand why dateserial() has month+1<BR><BR>Thanks

4. Member
Join Date
Dec 1969
Posts
63

## RE: Working with dates.. <..>

What the DATESERIAL function is doing is taking the month you passed in, and adds one to go to the first day of the next month. <BR><BR>Then DATEADD is subtracting 1 day from that date leaving you with the last day of the previous month. The you run the DAY function just to isolate the day.

5. Senior Member
Join Date
Dec 1969
Posts
205

## RE: Working with dates.. <..>

Yes i think it makes sense now.. thanks..

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•