Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Month Range Post Reply Post New Topic
Author Message
mikebird
Groupie
Groupie
Avatar

Joined: 04 Mar 2008
Location: United Kingdom
Online Status: Offline
Posts: 70
Quote mikebird Replybullet Topic: Month Range
    Posted: 29 Aug 2008 at 3:06am
I need to get a formula to give the first and last day of the current month. This was done no problem in SQL Server but not so straightforward in Crystal. Using this for the first day:
 
DATEADD("m", DATEDIFF("m", #00/00/0000#, currentdatetime), #00/00/0000#)
 
Crystal doesn't like the 00/00/0000 date but if I use 01/01/2000 it misses the point. I need to calculate from 0 to get eg. 1st Aug and 31st Aug when given any day in August. In SQL, this works fine:
 
SELECT DATEADD(m, DATEDIFF(m, 0, getdate()), 0), DATEADD(m, DATEDIFF(m, 0, getdate())+1, 0)-1
 
How do I do it in Crystal, please?
Life = luck (+/-) and effort (+/-). If you have no luck & make no effort, then you are dead
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 29 Aug 2008 at 7:32am
Hi
 
Formula for first day of month
 
 currentdate - Day(currentdate)+ 1
 
if datetimefield then use below for first day of month
 
DATE ( {table.datetimefield} - Day ( {table.datetimefield} ) + 1  )
 
Formula for Last day of month
 
date(DateAdd ('m' , 1 , currentdate - day(currentdate) + 1) - 1)

Cheers

Rahul
IP IP Logged
mikebird
Groupie
Groupie
Avatar

Joined: 04 Mar 2008
Location: United Kingdom
Online Status: Offline
Posts: 70
Quote mikebird Replybullet Posted: 02 Sep 2008 at 1:23am
How do I do this for datetime? First and last minute of a whole day?
Life = luck (+/-) and effort (+/-). If you have no luck & make no effort, then you are dead
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.