Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: I cant figure out how this formula is working Post Reply Post New Topic
Author Message
gloworm
Groupie
Groupie


Joined: 10 Oct 2011
Online Status: Offline
Posts: 47
Quote gloworm Replybullet Topic: I cant figure out how this formula is working
     Posted: 10 Oct 2011 at 6:42am
I have tried to follow this formula and it is bugging the heck out of me because i cant do it.

It may not even be working like I was told it was supposed to do.

This formula is supposed to return the date in a format like day of the year and 2 digit year, today would be 28311.

Here it is:

< ="Content-" content="text/; charset=utf-8">< name="ProgId" content="Word.">< name="Generator" content="Microsoft Word 14">< name="Originator" content="Microsoft Word 14"><>

ToNumber (Mid(ToText(DatePart("y",{to2Tran.TranDate}) & DatePart("yyyy",{to2Tran.TranDate})),4,2))



I get the "y" would pull 283 and "yyyy" pulls 2011.  It is the totext with ,4,2 that I do not understand.

How does this formula pull the right information?
I just don't see it.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Oct 2011 at 7:18am
I do not think it is doing what you want.
the 4,2 is referring to the MID function that is being used. It is stating to use the middle of the string (the totext) starting on the 4th character for 2 characters.
try
tonumber(totext(datepart('y',{to2tran.tranDate}))+totext({to2tran.tranDate},"yy"))
IP IP Logged
gloworm
Groupie
Groupie


Joined: 10 Oct 2011
Online Status: Offline
Posts: 47
Quote gloworm Replybullet Posted: 10 Oct 2011 at 7:31am
That is what I thought.  So I am not crazy after all.

I did something similar to what you said:

Julian day then 1 digit year

(totext(DatePart("y",{to2tran.tranDate}),0)) & (mid(totext(DatePart("yyyy",{to2tran.tranDate}),0),4,1))


1 digit Julian year then date

(mid(totext(DatePart("yyyy",{to2tran.tranDate}),0),4,1)) & (totext(DatePart("y",{to2tran.tranDate}),0))

I can modify the year section for a 1 digit or 2 digit year.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 10 Oct 2011 at 7:40am

as an FYI the last 2 digits of the year can be gotten as text without as much effort:

totext(datefield,"yy")
if you only want the last character:
right(totext(datefield,"yy"),1)
IP IP Logged
gloworm
Groupie
Groupie


Joined: 10 Oct 2011
Online Status: Offline
Posts: 47
Quote gloworm Replybullet Posted: 10 Oct 2011 at 9:23am
That worked like a charm too.

Thanks for your help.
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