?
Solved

Splicing a date range into date

Posted on 2014-04-01
11
Medium Priority
?
252 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 38

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 38

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 38

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 38

Accepted Solution

by:
PatHartman earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

801 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