Michael Franz
asked on
Splicing a date range into date
I have the following date...
1/1/2013 - 1/31/2013
I would like to get the date to be.. I want just the end of the date as my date.
1/31/2013
1/1/2013 - 1/31/2013
I would like to get the date to be.. I want just the end of the date as my date.
1/31/2013
ASKER
What is the difference in
Me.MyDate
Me.Date Range
My field name is called CompDate
Me.MyDate
Me.Date Range
My field name is called CompDate
Me.MyDate is the destination control and Me.DateRange is the source. So, Me.DateRange is Me.CompDate in your form. If you are not doing this in the code module of a form, you wouldn't use the Me. qualifier. But you didn't specify where you were doing this so I assumed a form since I thought I was answering an Access question. If you want to do this in T-SQL, you will need to figure out the equivalent T-SQL function. If you want to do this in an Access querydef, the InstrRev() function will work.
ASKER
I have a report writer. It see the date as a text string. I need to create a calculated field to cut the last part of the date off, so I get the month end. From what you provide me, I got....
Right(CompDate, InstrRev(CompDate, " ") + 1)
Right(CompDate, InstrRev(CompDate, " ") + 1)
What is your report writer? Are you using Access at all? If not, someone else will need to help you.
This will convert the string to a date as long as Access recognizes it as a valid format.
CDate(Right(Me.DateRange, InstrRev(Me.DateRange, " ") + 1))
Once the string is a date, you can use date functions such as Month(...) to extract the month part of the date. Why do you need just the month? If you are trying to create selection criteria, you almost certainly need the year as well.
This will convert the string to a date as long as Access recognizes it as a valid format.
CDate(Right(Me.DateRange, InstrRev(Me.DateRange, " ") + 1))
Once the string is a date, you can use date functions such as Month(...) to extract the month part of the date. Why do you need just the month? If you are trying to create selection criteria, you almost certainly need the year as well.
ASKER
Pat,
I do not need just the month. I want the last date in the date range. I need to split it off the from the range. I have it from another person....
var dateArr = CompDate.split(" - ");
dateArr[1];
I do not need just the month. I want the last date in the date range. I need to split it off the from the range. I have it from another person....
var dateArr = CompDate.split(" - ");
dateArr[1];
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for Newbi22's comment #a39970471
for the following reason:
Works... thank you.
Accepted answer: 0 points for Newbi22's comment #a39970471
for the following reason:
Works... thank you.
ASKER
I was gone and could not get back to it
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok
Me.MyDate = Right(Me.DateRange, InstrRev(Me.DateRange, " ") + 1)
If your data is not consistent, you may need to validate the string before trying to copy it to MyDate.