Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Comparing dates Post Reply Post New Topic
Author Message
hello
Groupie
Groupie
Avatar

Joined: 05 Feb 2014
Online Status: Offline
Posts: 85
Quote hello Replybullet Topic: Comparing dates
     Posted: 02 Apr 2014 at 11:52am
I am having trouble comparing dates in a CR 2011 version 14.

The date fields in my table are YYYY/MM/DD.

The date fields in CR date functions are MM/DD/YYYY.


Is there a way to do this?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Apr 2014 at 12:14pm
assuming your table fields are text you can use a formula to convert it to a date by using left and mid functions
example of converting your text to a 'crystal date field':
todate(mid(table.datefield,6)+'/'+left(table.datefield,4))


Edited by DBlank - 03 Apr 2014 at 4:22am
IP IP Logged
hello
Groupie
Groupie
Avatar

Joined: 05 Feb 2014
Online Status: Offline
Posts: 85
Quote hello Replybullet Posted: 03 Apr 2014 at 3:16am
Thank you DBlank.

IP IP Logged
hello
Groupie
Groupie
Avatar

Joined: 05 Feb 2014
Online Status: Offline
Posts: 85
Quote hello Replybullet Posted: 03 Apr 2014 at 6:26am
Well, I was wrong on my initial post.

The table date is in a DATE format of YYYY-MM-DD.

It must be converted to text, re-arranged, the dashes have to go, and then converted back to a CR date field (MM/DD/YYYY format).

So, I created this monstrosity of a formula:

Date (mid(totext({INV.INV_DATE_O}),6,2)+'/'
      +right(totext({INV.INV_DATE_O}),2)+'/'
      +left(totext({INV.INV_DATE_O}),4))

It comes back with "No Errors", but when I try to update the report data, an error of "Bad Date Format String" happens. What could I be missing?

Edited by hello - 03 Apr 2014 at 6:30am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 03 Apr 2014 at 6:59am
what kind of sample values are returned using 
totext({INV.INV_DATE_O})
IP IP Logged
hello
Groupie
Groupie
Avatar

Joined: 05 Feb 2014
Online Status: Offline
Posts: 85
Quote hello Replybullet Posted: 03 Apr 2014 at 8:11am
Originally posted by DBlank

what kind of sample values are returned using 
totext({INV.INV_DATE_O})


I did this, and to my surprise...

When I drag the table date field to the canvas (even without ToText), it displays as MM/DD/YYYY!

But, doing an SQL query, the result screen shows the same date field as YYYY-MM-DD.

I guess CR is automatically converting it somehow???

I must have a problem with a different part of my formula other than comparing dates.

Thanks for the help DBlank.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum