Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date Format Post Reply Post New Topic
Author Message
ajp42
Newbie
Newbie


Joined: 26 Mar 2013
Online Status: Offline
Posts: 28
Quote ajp42 Replybullet Topic: Date Format
    Posted: 24 Jun 2014 at 1:26am
currently working on creating a report in crystal

the current date format is backward eg "20140601"

I need to add on 1 year to the above making it "20150601"

I ended up using the below formula to convert the number to a date

if {SSJOBH.SERSDJ} = 999999999
    then Date(0,0,0)
    else
       (
        NumberVar yyyy := Truncate ({SSJOBH.SERSDJ}/10000); //extract year
        NumberVar mm := Truncate(({SSJOBH.SERSDJ} - (yyyy * 10000))/100); //extract month
        NumberVar dd := {SSJOBH.SERSDJ} - (yyyy * 10000) - (mm * 100); //extract day
        Date(yyyy,mm,dd)
       )

then once I did this - I was able to add on 365 days.

which resulted in it being "01/06/2015"

But to upload this info into system - I need to get it back to the number format - being "20150601"

FYI - this is for a lot of different data with multiple dates to change

Hope this makes sense

any ideas thanks
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 24 Jun 2014 at 2:50am
you can create a formula saying

totext({@UpdatedDate},'yyyyMMdd')

this will put it back in yyyymmdd format.
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 24 Jun 2014 at 2:56am
A faster way of doing it, could be something different.

This formula is converting it first to a date format, adds 365 days to it, and then converts it back to a text again. See if it works for you.

totext(date(tonumber(left({SSJOBH.SERSDJ},4)),
     tonumber(mid({SSJOBH.SERSDJ},5,2)),
     tonumber(right({SSJOBH.SERSDJ},2))
)+365,'yyyyMMdd')
IP IP Logged
ajp42
Newbie
Newbie


Joined: 26 Mar 2013
Online Status: Offline
Posts: 28
Quote ajp42 Replybullet Posted: 24 Jun 2014 at 3:41am
Nope neither of them work doesn't like the SSJOBH.SERSDJ fields
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 24 Jun 2014 at 3:42am
what format is the SSJOBH.SERSDJ field?
IP IP Logged
ajp42
Newbie
Newbie


Joined: 26 Mar 2013
Online Status: Offline
Posts: 28
Quote ajp42 Replybullet Posted: 24 Jun 2014 at 3:45am
Its a Number format
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 24 Jun 2014 at 3:47am
try this

totext(date(tonumber(left(totext({SSJOBH.SERSDJ},0,''),4)),
     tonumber(mid(totext({SSJOBH.SERSDJ},0,''),5,2)),
     tonumber(right(totext({SSJOBH.SERSDJ},0,''),2))
)+365,'yyyyMMdd')

Edited by Gurbs - 24 Jun 2014 at 3:48am
IP IP Logged
ajp42
Newbie
Newbie


Joined: 26 Mar 2013
Online Status: Offline
Posts: 28
Quote ajp42 Replybullet Posted: 24 Jun 2014 at 4:01am
Yes - that worked - thanks for the help
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.