Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to Convert Number to date Post Reply Post New Topic
Author Message
bkaukab
Newbie
Newbie
Avatar

Joined: 06 Jul 2011
Location: United States
Online Status: Offline
Posts: 10
Quote bkaukab Replybullet Topic: How to Convert Number to date
     Posted: 07 Jul 2011 at 2:51am
Hi,
 
I am making a report by hitting a view. In my view i have a MONTH column which is giving me month number as number
 
now i need to use that number to get previous month
 
what i am doing is Dateadd("MM",-1,(Month(CurrentDate())))
 
Error is a date required here
can someone help?
Bill
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Jul 2011 at 3:45am
dateadd requires 3 parts
the interval for adding ('MM')
the amount (-1)
and a date field which you do not have as you converted CUrrentdate to a number by using the MONTH()
IP IP Logged
bkaukab
Newbie
Newbie
Avatar

Joined: 06 Jul 2011
Location: United States
Online Status: Offline
Posts: 10
Quote bkaukab Replybullet Posted: 07 Jul 2011 at 3:49am
you are correct but can i use any other function to convert it back to a date so that i can have previous month ?
Bill
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Jul 2011 at 3:59am
do you want the previous month from today (which is kind of what your formula is doing)
or from the value in your database (which is what I am reading your post to ask for)?
if it is from your DB do you also need a year because what do you do if it is Jan (1)?
IP IP Logged
bkaukab
Newbie
Newbie
Avatar

Joined: 06 Jul 2011
Location: United States
Online Status: Offline
Posts: 10
Quote bkaukab Replybullet Posted: 07 Jul 2011 at 4:13am
yes previous month from today
 
then i will filter records saying where month = previous month
 
i have two date columns in data base 1. Just Year 2. Just Month
so what i am doing i am using select expert and filtering data first with year so it will give me only one years rows now i will filter it again with month .
 
 
Bill
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Jul 2011 at 4:18am
so you always want last months data only and both your year and month field are numeric fields (not text)
 
{table.yearfield} = year(dateadd('m',-1,currentdate))
and
{table.month} = month(dateadd('m',-1,currentdate))
IP IP Logged
bkaukab
Newbie
Newbie
Avatar

Joined: 06 Jul 2011
Location: United States
Online Status: Offline
Posts: 10
Quote bkaukab Replybullet Posted: 07 Jul 2011 at 4:40am
thanks that worked..
Bill
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