Now() but! always the 1st

Kenln

Registered User.
Local time
Today, 18:38
Joined
Oct 11, 2006
Messages
551
I use the Now() to put the report date into a table. In addition I would like to display the date but always as the 1st of whatever month and year.

Is there an easy way to take a date and just change whatever day to the first?

Here is what I am using now.

Code:
dtmReportDate = Left$(Now(), InStr(Now(), " ") - 1)
 
Public Shared Function GetBeginOfCurrentMonth(ByVal pDate As Date) As Date
Return Date.Parse(pDate.Year.ToString & "/" & pDate.Month.ToString & "/01")
End Function

You can then use
dtmReportDate = GetBeginOfCurrentMonth(Now())

or dtmReportDate = GetBeginOfCurrentMonth(date var)
 
in code
DateSerial(Year(Date), Month(Date), 1)
in a query/calculated control
DateSerial(Year(Date()), Month(Date()), 1)

HTH

Peter
 
You could also do:
dtmReportDate = Format(Now, "mm/" & "01" & "/yyyy")
or
dtmReportDate = Format$(Now, "mm/" & "01" & "/yyyy")
 

Users who are viewing this thread

Back
Top Bottom