Print Page | Close Window

First day of the year hardcoded

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5238
Printed Date: 04 May 2024 at 6:37am


Topic: First day of the year hardcoded
Posted By: question_for_u
Subject: First day of the year hardcoded
Date 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




Replies:
Posted By: lockwelle
Date 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.


Posted By: DBlank
Date 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)))


Posted By: malviarm
Date 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

-------------
Hi peoples


Posted By: DBlank
Date Posted: 28 Oct 2009 at 12:47pm

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



Posted By: lockwelle
Date 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?


Posted By: malviarm
Date 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


Posted By: DBlank
Date 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


Posted By: malviarm
Date Posted: 29 Oct 2009 at 12:07pm
Thanks Dblank....it solve my problem Clap

-------------
Hi peoples


Posted By: Vertex
Date 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


-------------
Hi Peoples


Posted By: DBlank
Date Posted: 29 Oct 2009 at 1:13pm
There may be other options for some of these but these should work. Check in the help fiels for more info:
 
If {?Trial} = "Today" then
{Order.CreateDateTime}= currentdate
else if {?Trial} = "Yesterday" then
{Order.CreateDateTime}=datedd('d',-1,currentdate)
 
else if {?Trial} = "This Week" then
{Order.CreateDateTime} > dateadd('d',-weekday(currentdate),currentdate)

else if {?Trial} = "Last week" then
{Order.CreateDateTime} in lastfullweek

else if {?Trial} ="This Month" then
{Order.CreateDateTime} in monthtodate

else if {?Trial} ="Last Month" then
{Order.CreateDateTime} in lastfullmonth


Posted By: Vertex
Date Posted: 29 Oct 2009 at 1:21pm
Thanks Sir ....

-------------
Hi Peoples



Print Page | Close Window