Results 1 to 2 of 2

Thread: DateSerial

  1. #1
    Join Date
    Dec 1969

    Default DateSerial

    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. #2
    Join Date
    Dec 1969

    Default RE: DateSerial

    Hey, L@ser,<BR><BR>The DateSerial function is a way for you to create a date in VBScript.<BR><BR>datDate = DateSerial(2001, 10, 25)<BR><BR>datDate is now October 25, 2001.<BR><BR>DateAdd adds a given interval to a given date. In the function you show above, -1 is being added to the given date. Since the given date is the first day of the month AFTER the month passed in, and since -1 is the interval, the date returned by the DateAdd function will be the last day of the given month.<BR><BR>Make sense?<BR><BR>Another way to get the days in a month is as follows:<BR><BR>Function GetDaysInMonth(intMonth, intYear)<BR>Dim datDate<BR>datDate = DateSerial(intYear, intMonth + 1, 0)<BR>GetDaysInMonth = Day(datDate)<BR>End Function<BR><BR>Which, in truth is virtually the same, except the line that starts with "datDate = ..." I think this way is a little bit cleaner myself.<BR><BR>BTW, I answered your question about why you should use separate tables instead of nested tables. Look in your thread with ReaperMan (at the end of today&#039;s posts).<BR><BR>I hope I have answered all of your questions!

Posting Permissions

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