Returning 'Day' value based on month and year parameters
Hi,
Is there a code that would return an end of the month Day value based on month and year parameters?
For example if my parameters yield 9 or September for a month value and 08 or 2008 for the year value, can a formula generate a value of 30 (the last day of the given month in the specific year)?
This way the formula would pick up the different last day of the month in February for the leap years.
Thank you.
Vic
1. Open the formula workshop.
2. From the Repository Custom Functions, under Crystal and then Date, RIGHT click on cdlastdayofmonth, click on ADD TO REPORT.
3. Create a new formula, in the formula workshop, under FUNCTIONS, go down the list till you see "CUSTOM FUNCTIONS", expand that till you see cdlastdayofmonth.
4. In your formula, type cdlastdayofmonth(currentdate)
5. Save and close and display the formula in your report, you should see 11/30/2008.
If you want just the day then modify the formula to:
totext(day(cdlastdayofmonth(currentdate)),0,'','');
since you have parameters for month and year, do this:
totext(day(cdlastdayofmonth(date({?year},{?month},01))),0,'','');
to give you the last day of the month.
Similar Messages
-
Selecting records based on month and year parameters
Hi. I have a sql 2008 r2 stored procedure which needs modifying to return the data based on a start / end month and year.
It's a large SP so I'll summarise - It accepts four parameters:
@StartMonth NVARCHAR(10)
@StartYear NVARCHAR(4)
@EndMonth NVARCHAR(10)
@EndYear NVARCHAR(4)
The current WHERE clause is:
WHERE ta.TimeByDay BETWEEN '01' + '-' + ltrim(LEFT(@StartMonth, 3)) + '-' + @StartYear
AND convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay))) + '-' + ltrim(LEFT(@EndMonth, 3)) + '-' + @EndYear
Example of input parameters:
@StartMonth = N'January',
@StartYear = N'2014',
@EndMonth = N'February',
@EndYear = N'2014',
Result:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
(1 row(s) affected)
However it executes correctly if we do either of the following:
1) Run the SQL direct in QA and type in January and February rather than passing in the Start/End Month parameters
2) As you can see we use the following datediff call to get the number of days per month. IF I replace this with '28', or '31' for example the query also runs (oddly number 1 above then also runs by executing the SP):
convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay)))
How do I update the WHERE clause to return records between a start/end month and year?
I'm a day on this so any help appreciated.
Thankscreate function NthDayOfMonth (@year int, @month smallint, @weekday varchar(15), @nth smallint)
returns datetime
as
begin
declare @the_date datetime, @c_date datetime, @cth smallint
set @cth = 0
set @c_date = convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'
while month(@c_date) = @month
begin
if datename(weekday,@c_date) = @weekday set @cth = @cth + 1
if @cth = @nth and datename(weekday,@c_date) = @weekday set @the_date = @c_date
set @c_date = dateadd(day,1,@c_date)
end
return @the_date
end
go
create function Dates(@date datetime)
returns @table table
now datetime,
today datetime,
Month_start datetime,
Month_end datetime,
Prev_Month_Start datetime,
Prev_Month_End datetime,
Week_Start datetime,
Week_End datetime,
Prev_Week_Start datetime,
Prev_Week_End datetime,
Quarter_Start datetime,
Quarter_End datetime,
Prev_Quarter_Start datetime,
Prev_Quarter_End datetime,
Year_Start datetime,
Year_End datetime,
Prev_Year_Start datetime,
Prev_Year_End datetime,
Month_End_TS datetime,
Prev_Month_End_TS datetime,
Week_End_TS datetime,
Prev_Week_End_TS datetime,
Quarter_End_TS datetime,
Prev_Quarter_End_TS datetime,
Year_End_TS datetime,
Prev_Year_End_TS datetime,
Year smallint,
Month smallint,
Day smallint,
Month_Name varchar(15),
Day_Name varchar(15),
WD smallint
as
begin
if @date IS NULL set @date = getdate()
insert into @table
select
@date as now,
convert(datetime,convert(varchar,@date,101)) as today,
dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
Year(@date) as Year,
Month(@date) as Month,
Day(@Date) as Day,
datename(month,@Date) as Month_Name,
datename(WEEKDAY,@date) as Day_Name,
datepart(weekday,@date) as WD
return
end
go
create function Holidays(@year smallint)
returns @table table
date datetime,
type varchar(10),
name varchar(25)
as
begin
insert into @table
select convert(datetime,convert(varchar,@year)+'-01-01') as date,'Holiday' as type ,'New Years Day' as name UNION ALL
select dbo.NthDayOfMonth(@year,2, 'Monday',3),'Holiday','Family Day' UNION ALL
select dateadd(d,0-case when datepart(weekday,convert(varchar,@year)+'-05-25') in (1,2) then 5+datepart(weekday,convert(varchar,@year)+'-05-25') else datepart(weekday,convert(varchar,@year)+'-05-25')-1 end, convert(varchar,@year)+'-05-25') ,'Holiday','Victoria Day' UNION ALL
select convert(varchar,@year)+'-01-07' ,'Holiday','Canada Day' UNION ALL
select dbo.NthDayOfMonth(@year,8, 'Monday',1),'Holiday','Civic Holiday' UNION ALL
select dbo.NthDayOfMonth(@year,9, 'Monday',1),'Holiday','Labour Day' UNION ALL
select dbo.NthDayofMonth(@year,10,'Monday',2),'Holiday','Thanksgiving' UNION ALL
select convert(varchar,@year)+'-11-11' ,'Holiday','Rememberance Day'UNION ALL
select convert(varchar,@year)+'-12-25' ,'Holiday','Christmas Day' UNION ALL
select convert(varchar,@year)+'-12-26' ,'Holiday','Boxing Day'
update @table
set date =
case when name != 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
when name != 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,1,date)
when name = 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
when name = 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,2,date)
when name = 'Boxing Day' and datepart(weekday,date) = 2 then dateadd(day,1,date)
else date
end
return
end
go
Using these functions (in place of a calendar table) you could do something like this:
DECLARE @forumTable TABLE (sales MONEY, saleDate DATE)
INSERT INTO @forumTable (sales, saleDate)
VALUES
(123.45, '2014-01-05'),(678.90, '2014-01-06'),(111.21, '2014-01-07'),(314.15, '2014-01-08'),(161.71, '2014-01-09'),
(819.20, '2014-02-05'),(212.22, '2014-02-06'),(324.25, '2014-02-07'),(262.72, '2014-02-08'),(829.30, '2014-02-09')
SELECT SUM(f.sales), d.month_end
FROM @forumTable f
CROSS APPLY sandbox.dbo.dates(f.saleDate) d
GROUP BY d.month_end -
Need working days for a particular month and year
Hi,
I need the number of working days for a particular month and year.Saturdays and Sundays are holidays.
Regards,
VigneshTry this:
SQL> var yr NUMBER;
SQL> exec :yr := 2010;
PL/SQL procedure successfully completed.
SQL> with t as (select :yr yr from dual)
2 SELECT TO_CHAR(dat,'MON-RR'),COUNT(*) FROM
3 (select TO_DATE('01-JAN-'||yr) + lv dat FROM
4 (select level - 1 lv,yr from t
5 connect by level <= TO_DATE('31-DEC-'||yr) - TO_DATE('01-JAN-'||yr) + 1))
6 WHERE TO_CHAR(Dat,'DY') NOT IN ('SAT','SUN')
7 GROUP BY TO_CHAR(dat,'MON-RR');
TO_CHAR(DAT, COUNT(*)
APR-10 22
AUG-10 22
DEC-10 23
FEB-10 20
JAN-10 21
JUL-10 22
JUN-10 22
MAR-10 23
MAY-10 21
NOV-10 22
OCT-10 21
TO_CHAR(DAT, COUNT(*)
SEP-10 22
12 rows selected.
SQL> Edited by: AP on Jul 27, 2010 7:54 AM -
Table for Material Quantity and Value for particular month and year
Hi All
My requirement is that for a particular month and year I want to know the stock quantity and stock value for a particular material for a given plant.From which SAP table can I get this data as I want to fetch data for my Y report?
Regards
Satish KumarHi,
You can use MB5B table as suggested earlier.also you can use:
MBEW-VMKUM --> stock for previous month period
MBEW-VJKUM --> stock for previous year period
PLease view these links which migh tbe helpful to you:
http://help.sap.com/saphelp_47x200/helpdata/en/39/55fee3bc6111d4b3960050dadf0791/content.htm
TableStock
Thanks
Nisha -
Conditional Processing based on month and Year
Hi ALL,
I have one package that Contain two DataFlow
DFT1
DFT2
now What I need ,I need to Process the DFT1 on every week and DFT2 on every month Start.
Please Help Me .
How can I do this task.
ThanksHi BI_group,
The two Data Flow Tasks should not be connected, right? We can add two Execute SQL Tasks to store the day or weekday of today in a variable, connect them with the two Data Flow Tasks respectively, and configure Precedence Constraint based an expression.
For example, we configure Execute SQL Task 1 as follows:
On “General” tab:
ResultSet: Single row
ConnectionType: OLE DB
Connection: (Any OLE DB connection manager)
SQLStatement: SELECT DATENAME(WEEKDAY,GETDATE()) AS TodayOfWeekday
On “Result Set” tab:
Result Name: 0
Variable: User::TodayOfWeekday
Then, double click the path between Execute SQL Task 1 and Data Flow Task 1, and configure the Precedence Constraint as follows:
Evaluation operation: Expression
Expression: @[User::TodayOfWeekday]=”Sunday”
For Execute SQL Task 2, you can use the query “SELECT DAY(GETDATE()) AS TodayOfMonth” to get the month day of today, store it in the variable TodayOfMonth, and configure the expression of the Precedence Constraint between Execute SQL Task 2 and Data Flow
Task 2 as:
@[User::TodayOfMonth]="1"
Regards,
Mike Yin
TechNet Community Support -
How to save and month and year wise values
Hi friends,
in my ztable i have to enter values manually for month and year wise..
so i have to create parameter for month and year how to create it.
in my parameter month and year fields..
once he given month and year then he should enter values for fields..
i have doubt how to give parameter for this...table..
example: month: 1
year : 2007
after that user enter values for following fields.
kunnr
name
core values
noncorevalues
above fields user will enter values month wise ..
once he enter the values for january it should save ...
next he enter values for february and it will save..
when ever he want to see the january month data how can he see..
is there any logic for the above problem...Hai venkat,
I am not totally clear with your question some how i understood. I give my opinion may be it ll help ful to you.
In your ztable you want to enter the values for the fields kunnr, name, core values ,noncorevalues as per month.
As i say in your ztable add another field as month with other 4 fields. Provide the table maintenance for your table or else in se11 -> table display ->utilities -> table contents -> create entries is one way.
If you proivided maintenance for your table go to SM30. where you can manually enter values .
<b>reward if useful</b>
Regards,
sunil kairam. -
Find the difference between two dates for the specific month and year
Hi,
I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
for that date. In this case I input Jan 2013. How can I sql this ?I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
First let me understand you:
You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
declare @for_month int = 1 --January
declare @for_year int = 2013
declare @StartDate date = '2012-12-20'
declare @EndDate date = '2013-01-04'
SELECT
CASE
WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
DATEDIFF(DAY, @StartDate,@EndDate)
WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
ELSE
0
END as [DD]
I don't know how you calculate day range between 01/01/2013 and 04/01/2013
is 4, it is actually is 3 but if that is the case, you can add 1 from the condition. -
I want to accumulate rain for the day, month and year; What formula can I use?
I want to accumulate rain for the day, month and year; What formula or expression can I use.
I am using a Rain Wise product that converts pulses to an analog value. The Rain Wise device can be
set to measure up to 1", 5", or 10". I will be setting the unit to 10 inches in increments of 0.01 inches.
What I would like to do is everytime the signal increments I would like to count it as 0.01 then after reaching
a period of time whether it be a day or a month reset back to zero.
Need some advise on this problem.
Solved!
Go to Solution.Hello Ryan,
Lookout gets a Modbus over Ethernet signal which originates as a 4-20mA input to a Moxa Ethernet I/O Module (E1240) in the field. In Lookout I created a ModbusEthernet Driver and a tag which scales 0 - 65534 RAW to 0-10 Eng. [0 - 10 is inches of rain] Also, another piece of information is that after the rain gauge maxes out at 10 inches it will zero out and start over.
I though the accumulator was time based and took a sample over a specific time period, for instance, one sample every 30 seconds then accumulate. If this is so then if I have 5 inches of rain and then it stopped raining, then 30 seconds latter it would sample, it would see 5 inches and add that to be 10 inches when actually it had only rained 5 inches.
I really need some help with this process,
David Lopez
City of Corpus Christi -
When my delegates are filling in a event form i have put together, a large number of them forget to change either the month or year on the date field. Is there a way to have a date field that has drop down boxes for day, month and year so they have to choose rather than a date been already on the screen??
ThanksHi Christopher,
The WEEKDAY function allows specifying either Sunday or Monday as the first day of the week:
WEEKDAY
The WEEKDAY function returns a number that is the day of the week for a given date. WEEKDAY(date, first-day)
 date: The date the function should use. date is a date/time value. The time portion is ignored by this function.
 first-day: An optional value that specifies how days are numbered.
Sunday is 1 (1 or omitted): Sunday is the first day (day 1) of the week and Saturday is day 7.
Monday is 1 (2): Monday is the first day (day 1) of the week and Sunday is day 7. Monday is 0 (3): Monday is the first day (day 0) of the week and Sunday is day 6.
But I think you are referring to the first day of the 'workweek', for which I do not see a means of defining a custom value.
Since you want to 'insert categories', though, you could easily define your own, using WEEKDAY(date) or WEEKDAY(date,1), plus an IF statement to return the category label appropriate to the day. Here's one for a Sunday to Thursday work week. Dates are in column A, the formula is in whichever column you want as the Category column. For the example, I've placed it in column B.
B2, and filled down: =IF(WEEKDAY(A)<6,"Work","Off")
The top table shows the weekday numbers returned for each day of the week for each of the three permitted values for the optional second argument. The bottom table shows the results from the formula above, used to define a category label for each date:
A10 was left blank intentionally, to determine if the lack of data resulted in an error. The Warning message, flagged by the blue 'warning' triangle, is "The formula uses a number in place of a date." The 'date' assigned to this numerical value of zero was a Friday, but I'm not certain when. Probably best to avoid extra rows with no date shown.
Regards,
Barry -
Getting Day, month and year from Date object
hello everybody,
Date mydate = Resultset.getDate(indexField);
Now i would like to get day, month and year from mydate.
In another words, i'm looking for something equivalent to
mydate.getDay() as this method is deprecated.
Can somebody help me out please?
Thank you in advance,swvc2000,
Here is a sample class that demonstrates two ways in which to do this.import java.util.*;
import java.text.*;
public class DateSplitter {
public static void main(String args[]) {
/* even though your date is from a result set,
pretend the following date is your date that
you are using. The try catch block is used
because I hand-crafted my date using
SimpleDateFormat. Substitute your date.*/
Date yourDate = null;
try {
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
yourDate = formatter.parse("05/06/2000");
} catch (ParseException e) { }
//the following gets the current date
Calendar c = Calendar.getInstance();
//use the calendar object to set it to your date
c.setTime(yourDate);
//note months start at zero
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);
System.out.println("Calendar Month: "+month);
System.out.println("Calendar Day: "+dayOfMonth);
System.out.println("Calendar Year: "+year);
System.out.println();
/* Simple date format can also be used to strip them
out of your date object. When you use it, notice that
months start at 1. Also, it returns string values. If
you need integer values, you will have to use
Integer.parseInt() as I did below. If you are
only concerned about the string values, just remove
the Integer.parseInt part. */
DateFormat formatter = new SimpleDateFormat("M");
month = Integer.parseInt(formatter.format(yourDate));
System.out.println("SDF Month: "+ month);
formatter = new SimpleDateFormat("d");
dayOfMonth = Integer.parseInt(formatter.format(yourDate));
System.out.println("SDF Day: "+ dayOfMonth);
formatter = new SimpleDateFormat("yyyy");
year = Integer.parseInt(formatter.format(yourDate));
System.out.println("SDF Year: "+ year);
}//end main
}//end DateSplitter classtajenkins -
Sorting grouped values by month and year within chart
Hello
I have a really tough problem which I can't seam to figure out.
I have a table called SOLAR_RETURN which has 4 columns:
- ID
- USER_ID
- DATUM
- RETURN
On a page I have 3 links, one for showing the information from the database by day, month or year.
The hidden field :P25_DATE_FILTER is being set through the URL when clicking one of the 3 links.
I have a linechart with the following sql statement which pulls the correct data according to the value of :P25_DATE_FORMAT:
select null link, to_char("SOLAR_RETURN"."DATUM", :P25_DATE_FILTER) as label, max("SOLAR_RETURN"."RETURN") as value from "SOLAR_RETURN"
WHERE "SOLAR_RETURN"."USER_ID" = :USER_ID
AND to_char(DATUM, :P25_DATE_FILTER) = decode(:P25_DATE_FILTER,'YYYY',to_char(DATUM, 'YYYY'),'MM-YYYY',to_char(DATUM, 'MM-YYYY'),'DD-MM-YYYY',to_char(DATUM, 'DD-MM-YYYY'))
GROUP BY to_char(DATUM, :P25_DATE_FILTER)
Everything is working great, only the sorting is messed up. I need to sort it so that when :P25_DATE_FORMAT is set to DD-MM-YYYY it will be sorted by year desc, month desc, day desc. If the value would be MM-YYYY it would need to sort by year desc, month desc.
I have tried the following without succes:
ORDER BY to_char(DATUM, :P25_DATE_FILTER) ASC
--> This doesnt cut it since it sorts like this: (for example)
01-2010
02-2010
11-2009
12-2009
Vice versa for DESC
Is there any way that I can sort the grouped values by day, month and year seperately?
Thanks in advance!
MarcHi,
What is data type for column DATUM ?
If it is date did you try ORDER BY DATUM DESC ?
Br,Jari -
Elapse days - calculation from month and year
Duplicate thread ...
coding required for converting month into days
I have Month and year field in my DSO --Year( 2009), Month(4)
I want below logic to calculate -
MTD qty % = (qty * elapse days) / no of days in month
so from the above, I want to know,
1. How can we get the no of days from the above 2 objects (year and month).
2. Elapse days are the days that are over from current date to Ist day of that month.
eg: current date - 04.03.2009 , 1st day of the month - 04.01.2009,
elapse days = 2. (you need to consider all days in the month, not only working days)
so my questions is how can we get, # of days n a month from above 2 fields and elapse days based on the above condition.
also want to know, where can I have the logic in transformations or query level.
please provide your suggestions.
Thanks,
Pra
Edited by: Arun Varadarajan on Apr 5, 2009 10:44 PM
Edited by: Arun Varadarajan on Apr 5, 2009 10:45 PMHello,
I think the sample program below does what you ask: it finds the days in the month (bit of an overkill to use function modules for that) and then computes the QTD.
Note that the internal string representation of a data variable is always YYYYMMDD, regardless of the "externalized" form (e.g. yyyy/mm/dd or dd.mm.yyyy), so this code will work regardless of your custom date format.
Regards,
Mark
REPORT zqty_to_date.
PARAMETERS:
p_date TYPE dats,
p_qty TYPE i.
DATA:
days TYPE i,
n_year TYPE numc4,
n_month TYPE numc2,
n_day TYPE numc2,
qtd(6) TYPE p DECIMALS 1.
START-OF-SELECTION.
n_year = p_date+0(4).
n_month = p_date+4(2).
n_day = p_date+6(2).
PERFORM days_in_month USING n_year n_month CHANGING days.
qtd = ( p_qty * ( n_day - 1 ) ) / days.
WRITE: / 'Days in month:', days,
/ 'Qty to date :', qtd.
*& Form days_in_month
* text
FORM days_in_month USING year month CHANGING days.
DATA: ymod4 TYPE i,
ymod100 TYPE i,
ymod400 TYPE i.
CASE month.
WHEN 4 OR 6 OR 9 OR 11.
days = 30.
WHEN 2.
ymod4 = year MOD 4.
ymod100 = year MOD 100.
ymod400 = year MOD 400.
IF ( ymod4 = 0 AND ymod100 > 0 ) OR ( ymod100 = 0 AND ymod400 = 0 ).
days = 29.
ELSE.
days = 28.
ENDIF.
WHEN OTHERS.
days = 31.
ENDCASE.
ENDFORM. "days_in_month -
Hide days from WebElements component WECalendar (show only month and year)
Dear expert,
I'm using WebElements to replace standard InfoView parameter screen for my Crystal Reports. My question is:
1. Is it possible to customize WebElements component: WECalendar so that we only see Month and Year, but not the Days (in other words to hide the days from the calendar).
If not possible then is there any other WebElements component that i can use for this purpose?
Because i only need to pass value of month and year selected by user when jumping to other report (using OpenDocument).
2. When i looked at the code, i'm afraid the only way is by editing the HTML part that is marked with:
// *** do not modify the code below
Since there's no available variables for hiding the days in the section that can be modified:
// *** the code below can be modified to change the formatting to the desired look and feel
Below is some of the code of the WECalendar component:
Function (stringvar ElementName, datevar ElementDefault, stringvar MonthDisplays, stringvar DayDisplays)
// *** the code below can be modified to change the formatting to the desired look and feel
// calendars use the stringvars below if nothing is entered into the WECalendar function for these parameters
if DayDisplays="" then DayDisplays:= 'Su|Mo|Tu|We|Th|Fr|Sa'; // note that there must be two characters for each day...or use " " as in 'S |M |T |W |T |F |S '
if MonthDisplays="" then MonthDisplays:= 'January|February|March|April|May|June|July|August|September|October|November|December';
// the font below is for the month & year display in the calendar and can be modified
stringvar headerfont:= WEFont('Verdana', 11, 'Navy', '', true, false,"","");
// the font colour and size below can be modified...this is for the arrows that change the month or year of the calendar
stringvar arrowfont:= WEFont('Arial', 10, 'Gray', '', false, false,"","");
// these fonts for the calendar days must be a fixed width font such as Lucida Console or the calendar spacing will break
stringvar datefont:= WEFont('Lucida Console', 8, 'Black', '', false, false,"","");
stringvar daystringfont:= WEFont('Lucida Console', 8, 'Black', '', false, false,"underline","");
stringvar weekendfont:= WEFont('Lucida Console', 8, 'Gray', '', false, false,"","");
stringvar inputfont:= WEFont('Lucida Console', 8, 'Navy', 'Center', false, false,"","");
// *** do not modify the code below
Thank you very much.
Kind regards,
aswin
Edited by: Aswin Setyawan Margono on Feb 2, 2011 5:16 PMhi Aswin,
you can always modify any of the webelements controls or create your own if you're feeling adventurous. the "do not modify" is just a warning that the code below is not as customizable as the code above which is made to be easily changed.
my recommendation for an easy win in your case though is to use the weSelectDuo control having years in the first of the select menus and the months in the second select menu.
cheers,
jamie -
Returning a value based on user-supplied sql variables
I'm using JDeveloper 10.1.3.1, ADF and JSP.
I want to return a primary key based on values a user enters in unbound fields (like inputText). They'll be entering information for a record including a 10-segment GL code, and when the other bound values are committed, I'd like the associated GL id to be returned for the row (if found). Validation is not necessary at this point. A null return is okay.
I've defined bind variables in a GL view object - one for each of the 10 segments - plus a jspx form with 10 inputText objects.
Does it sound like this is going in a logical direction? I'm stuck at this point, and am open to suggestions.1. Open the formula workshop.
2. From the Repository Custom Functions, under Crystal and then Date, RIGHT click on cdlastdayofmonth, click on ADD TO REPORT.
3. Create a new formula, in the formula workshop, under FUNCTIONS, go down the list till you see "CUSTOM FUNCTIONS", expand that till you see cdlastdayofmonth.
4. In your formula, type cdlastdayofmonth(currentdate)
5. Save and close and display the formula in your report, you should see 11/30/2008.
If you want just the day then modify the formula to:
totext(day(cdlastdayofmonth(currentdate)),0,'','');
since you have parameters for month and year, do this:
totext(day(cdlastdayofmonth(date({?year},{?month},01))),0,'','');
to give you the last day of the month. -
How to get Week,Month and Year details from a date column
Hi frenz,
I've a column like tran_date which is a date column..... I need the next week details based on this column and so on...
I need month and year details as well based on this tran_date column.... can any one tell me how...
Thanks in advanceMy example for objects:
create or replace type date_object as object
centure number,
year number,
month number,
day number,
hour number,
minute number,
second number,
daypart number,
week number,
constructor function date_object(p_dt date)
return SELF as result
create or replace type body date_object is
constructor function date_object(p_dt date)
return SELF as result
as
begin
SELF.centure:= trunc(to_char(p_dt,'YYYY')/100);
SELF.year:= to_char(p_dt,'YYYY');
SELF.month:= to_char(p_dt,'MM');
SELF.day:= to_char(p_dt,'DD');
SELF.hour:= to_char(p_dt,'HH24');
SELF.minute:= to_char(p_dt,'MI');
SELF.second:= to_char(p_dt,'SS');
SELF.daypart:= p_dt-trunc(p_dt,'DD');
SELF.week:= to_char(p_dt,'IW');
return;
end;
end;
select date_object(sysdate),
date_object(sysdate).year
from dual;Regards,
Sayan M.
Maybe you are looking for
-
Error in installing oracle 11.1 on Linux
This is the error message I get when installing oracle 11g 11.1.0.6.0 on Linux 5 (CentOS 5.2 Final) and the installation stalls at 9% fro m the installation logs java.util.zip.ZipException: invalid entry size (expected 6802107 but got 6802124 bytes)
-
How do I get component video (YPbPr) from my iMac mini display port?
I have a converter cable with dini DP on one end and HDMI on the other, this goes into an HDIM conveter box that converts HDMI to Component. THe TV does not recogize the signal as compatable.
-
I upgraded to itunes 6.0.4, it only launches when connected to the internet
i recently upgraded my itunes to 6.0.4, ever since i did that, the itunes doesn't launch except when i have internet access, when i try to launch it anywhere else it says application not responding, what do i do?
-
Why can't i sync my calendar on my iMac and iPad Air
I am unable to sync my Contacts and Calendars on my iMac 10.10.1 and my iPad Air 8.1. ? When I sync my "info" I receive the message: "You Contacts are being synced with your iPad over the air from iCloud." but it never happens.
-
Read Sales Order Item Conditions
Hi All, Quick question. If I have a sales order and item number how can I read the item condtions. Is there a function module I can use or is there a table? Many Thanks, Colm