Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: First day of the year hardcoded Post Reply Post New Topic
Page  of 2 Next >>
Author Message
question_for_u
Newbie
Newbie


Joined: 16 Jan 2009
Online Status: Offline
Posts: 1
Quote question_for_u Replybullet Topic: First day of the year hardcoded
    Posted: 16 Jan 2009 at 5:23am

Someone has hardcoded in the first day of the year in a formula field.  Basically, they wrote an IF statement where the date coming from a database field has to be less than or equal to the first day of the year.  Now, I want to remove the hardcoded date (it's now 01/01/2009), and put in dynamic code.  I don't want a prompt field or anything like that.  Can this be done using a formula field in crystal reports?  If so, how???  It's driving me nuts......Cry

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 16 Jan 2009 at 6:14am
if it is still for the first of the year, you could change the formula to something like:
 
if {datefield} = Date( Year(Now), 1, 1) then ...
 
Hope this helps or points the way.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 16 Jan 2009 at 8:18am
if you just always want Jan 1,xxxx (the year that the report is run in) use this as a formula field:
Dateadd ('d',1,(currentdate) - (datepart("d",currentdate)))
 
Ouch Oops! That is incorrect, it will give you the first day of the month of this year and month
 
This should be correct;
Dateadd ('d',1,(currentdate) - (datepart("y",currentdate)))


Edited by DBlank - 16 Jan 2009 at 9:40am
IP IP Logged
malviarm
Newbie
Newbie
Avatar

Joined: 21 Oct 2009
Location: India
Online Status: Offline
Posts: 3
Quote malviarm Replybullet Posted: 28 Oct 2009 at 12:26pm
plz help me to get last day of this year and starting of last year...thanks in advance ...Rameshwar

Edited by malviarm - 28 Oct 2009 at 12:27pm
Hi peoples
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Oct 2009 at 12:47pm

Please give example data as I do not know what dates you are looking for here.

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Oct 2009 at 6:13am
local numbervar lastYr := year(CurrentDate) - 1;
local numbervar startYr := CDate(1,1,lastYr);
local numbervar endYr := CDate(12,31,lastYr);
 
is this what you are looking for?
IP IP Logged
malviarm
Newbie
Newbie
Avatar

Joined: 21 Oct 2009
Location: India
Online Status: Offline
Posts: 3
Quote malviarm Replybullet Posted: 29 Oct 2009 at 10:38am
Plz give me this in datetimevar type....i want to solve this problem....

if {?Trial} ="This Year" then

{Order.CreateDateTime}>...1 jan ........ and .......31 dec......<{Order.CreateDateTime}

else if {?Trial} ="Last Year" then
{Order.CreateDateTime} > ...........and{Order.CreateDateTime}< ..........

plz give me complete solution...thanks
Hi peoples
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Oct 2009 at 11:25am
You probably want one of these two options to be used in your select expert:
if {?Trial} ="This Year" then
{Order.CreateDateTime} in yeartodate
else if {?Trial} ="Last Year" then
{Order.CreateDateTime} in lastyearYTD
//this is only last year jan 01 to last year today's date
 
or
 
if {?Trial} ="This Year" then
{Order.CreateDateTime} in yeartodate
else if {?Trial} ="Last Year" then
year({Order.CreateDateTime}) = year(dateadd('y',-1,currentdate))
//all of last year


Edited by DBlank - 29 Oct 2009 at 11:26am
IP IP Logged
malviarm
Newbie
Newbie
Avatar

Joined: 21 Oct 2009
Location: India
Online Status: Offline
Posts: 3
Quote malviarm Replybullet Posted: 29 Oct 2009 at 12:07pm
Thanks Dblank....it solve my problem Clap
Hi peoples
IP IP Logged
Vertex
Newbie
Newbie
Avatar

Joined: 29 Oct 2009
Location: India
Online Status: Offline
Posts: 24
Quote Vertex Replybullet Posted: 29 Oct 2009 at 12:43pm
Please Give me the shortest formula for this ......statements..

If {?Trial} = "Today" then
{Order.CreateDateTime}= ...........For Today

else if {?Trial} = "Yesterday" then
{Order.CreateDateTime}.............For Yesterday

else if {?Trial} = "This Week" then
{Order.CreateDateTime}>...........First Day of Week and
{Order.CreateDateTime}.............Last Day Of week

else if {?Trial} = "Last week" then
{Order.CreateDateTime}>...............last week first day and {Order.CreateDateTime}< ......last week end day

else if {?Trial} ="This Month" then
{Order.CreateDateTime}>.........First day This month and {Order.CreateDateTime}<DateAdd ...........Last day this month

else if {?Trial} ="Last Month" then
{Order.CreateDateTime}>.........First day Last month and {Order.CreateDateTime}<DateAdd ...........Last day Last month  Ouch


Edited by Vertex - 29 Oct 2009 at 12:46pm
Hi Peoples
IP IP Logged
Page  of 2 Next >>
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.016 seconds.