Getting the first and last date of the month using a script
Hi,
Can someone share a script to get the first and last date from a date column in a datasource?
I have tried but I can’t seem to get the format right.
Cheers
Can someone share a script to get the first and last date from a date column in a datasource?
I have tried but I can’t seem to get the format right.
Cheers
Answers
Arthur,
I’d do something like this:
https://stackoverflow.com/questions/3720785/get-the-last-en-for-last-day-of-a-month
This one uses the “current year/month” and yours is from your data. But you’d then just use _MYDATE.Year and _MYDATE.Month instead and it should come out the same.
I’d do something like this:
https://stackoverflow.com/questions/3720785/get-the-last-en-for-last-day-of-a-month
This one uses the “current year/month” and yours is from your data. But you’d then just use _MYDATE.Year and _MYDATE.Month instead and it should come out the same.
I used the following for anyone else who wants to do this:
‘First Date
Dim sourcedate as Datetime
sourcedate = DateTime.Now.ToShortDateString() ‘replace with date field from datasource
Return New DateTime(sourceDate.Year, sourceDate.Month, 1)
‘Last Day
Dim sourcedate as Datetime
sourcedate = DateTime.Now.ToShortDateString() ‘replace with date field from datasource
Dim lastDay As DateTime = New DateTime(sourceDate.Year, sourceDate.Month, 1)
Return lastDay.AddMonths(1).AddDays(-1) ‘change addmonths accordingly