Solved

Splicing a date range into date

Posted on 2014-04-01
11
246 Views
Last Modified: 2014-04-24
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
0
Comment
Question by:Michael Franz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 37

Expert Comment

by:PatHartman
ID: 39970387
You can use InStrRev() to find the rightmost space and then copy everything past that space to the date field.

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.
0
 

Author Comment

by:Michael Franz
ID: 39970403
What is the difference in

Me.MyDate

Me.Date Range

My field name is called CompDate
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 39970455
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.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Michael Franz
ID: 39970471
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)
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 39970814
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.
0
 

Author Comment

by:Michael Franz
ID: 39972581
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];
0
 

Author Comment

by:Michael Franz
ID: 40020998
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.
0
 

Author Comment

by:Michael Franz
ID: 40020879
I was gone and could not get back to it
0
 
LVL 37

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40020990
Sorry, the function should have been Mid()
Mid("1/1/2013 - 1/31/2013", InstrRev("1/1/2013 - 1/31/2013", " ") + 1)
0
 

Author Closing Comment

by:Michael Franz
ID: 40020999
ok
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question