[AccessD] A2203: Date Format Issues

Darryl Collins Darryl.Collins at coles.com.au
Fri Jul 18 19:59:56 CDT 2008


"This can be done a lot simpler." hehe, thanks heaps for that Gustav. Frankly I am not at all suprised that the Help example is clunky. I am constantly suprised at how convoluted some of the code examples (and auto generated code) is that microsoft produces - I mean, they folks wrote the book, you would think they would do it more elegantly than anyone else, but no. Almost like they want it to be stupidly complex. hmmmm.

cheers
Darryl

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Gustav Brock
Sent: Friday, 18 July 2008 7:01 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] A2203: Date Format Issues


Hi Darryl

This can be done a lot simpler. The trick is the day of zero which forces DateSerial to return the date before the first of the month.

<code>

Public Function DaysInMonth(ByVal datDate As Date) As Integer

' Returns count of days of month of datDate.
' 2005-01-06. Cactus Data ApS, CPH.

  Dim intDays As Integer

  intDays = Day(DateSerial(Year(datDate), Month(datDate) + 1, 0))
  DaysInMonth = intDays

End Function

</code>

/gustav


>>> Darryl.Collins at coles.com.au 18-07-2008 03:15 >>>
Hi Darren,

Did you try Drews suggestion?

>From Access Help:

'========================================================
DateSerial, Day, Month, and Year Function Examples

The following example uses the DateSerial function together with the Year, Month, and Day functions to return the number of days in a month. You can pass either a date or a string to the DaysInMonth function.

Function DaysInMonth(dteInput As Date) As Integer
    Dim intDays As Integer

    ' Add one month, subtract dates to find difference.
    intDays = DateSerial(Year(dteInput), _
        Month(dteInput) + 1, Day(dteInput)) _
        DateSerial(Year(dteInput), _
        Month(dteInput), Day(dteInput))
    DaysInMonth = intDays
    Debug.Print intDays
End Function
The following Sub procedure shows several different ways that you might call the DaysInMonth function.

Sub CallDaysInMonth()
    Dim intDays As Integer
    intDays = DaysInMonth(#4/1/96#)
    intDays = DaysInMonth("4-1-96")
    intDays = DaysInMonth("April 1, 1996")
End Sub
'================================================================



--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

This email and any attachments may contain privileged and confidential information and are intended for the named addressee only. If you have received this e-mail in error, please notify the sender and delete this e-mail immediately. Any confidentiality, privilege or copyright is not waived or lost because this e-mail has been sent to you in error. It is your responsibility to check this e-mail and any attachments for viruses.  No warranty is made that this material is free from computer virus or any other defect or error.  Any loss/damage incurred by using this material is not the sender's responsibility.  The sender's entire liability will be limited to resupplying the material.




More information about the AccessD mailing list