Solved

Convert str to date and then compare

Posted on 2008-06-09
3
1,602 Views
Last Modified: 2012-06-22
I need to compare 2 date fields; one is a string, the other is a datetime.  The string is in the yyyymmdd format.  How do I convert these two data types, and then compare them?  I will want to display data where the data associated with the string is more recent than the datetime.
0
Comment
Question by:AMS_RN
[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
  • 2
3 Comments
 
LVL 10

Expert Comment

by:MaduKp
ID: 21749126
Could you please give more details?
what is the database?
what is the programming language you are using?
0
 

Author Comment

by:AMS_RN
ID: 21750977
Sorry about that;  I'm using Crystal Reports XI, and the database is in sql (it's a healthcare database.)  I am comparing the date that a medication was stopped (which is a string) to the date of the office visit (which is a datetime).  I only want to display medications that have a stop date AFTER the office visit date (so the medication is still current when the patient leaves the clinic).
0
 
LVL 10

Accepted Solution

by:
MaduKp earned 125 total points
ID: 21757590
Ok ,
Please see below SOL statement, you can use this as a SP and use,
Use <Your DB - healthcare database>

========================================================================

DECLARE  @medication_stopped datetime
SET @medication_stopped = '2008-06-11'  send your date here

To compare two dates is done as below ,Here the table_2 is <whatever your table have the filed date of the office visit> 

select * from table_2
where convert(varchar(8), date_of_the_office_visit)
< convert(varchar(8), @medication_stopped)

=========================================================================

Suppose your table is something like this,
ID            date_of_the_office_visit
1      06/10/2008 12:00:00 AM
2      06/11/2008 12:00:00 AM
3      06/07/2008 12:00:00 AM
4      06/19/2008 12:00:00 AM
5      09/10/2008 12:00:00 AM
6      02/10/2008 12:00:00 AM

The output will be
1      2008-06-10 00:00:00.000
3      2008-06-07 00:00:00.000
6      2008-02-10 00:00:00.000
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

752 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