How to concatenate the date in datenum with the year in MATLAB - matlab

I need to get the payment dates of a bond. The payments dates are quarterly. I have already set up the date in a cell. But I need to concatenate it with the particular year, which I am not sue how to.
EffectiveDate = datenum('15/05');
I need to concatenate it with the year like 2012.
What i Tried:
join(EffectiveDate,year(datenum('15/05/12'))
EffectiveDate + year
Both didn't give me a correct answer.
How do i do it? Need some help on this. Thanks.

If all values are given as strings:
date = '15/05';
year = '2012';
fullDate = [date,'/',year]; %String concatenation
now you can convert to serial form using datenum:
sDate = datenum(fullDate,'dd/mm/yyyy');
Hope this is what you asked for

Related

DAX Calculate Billing Days Between Two Variable Dates

I have a dimdate table that is represented below. I have each day flagged as BusinessDay Y/N. I also have a DimSalesRep table that has a daily goal for each rep. I want to be able to allow users to input a StartDt and EndDt with filters on the report and have a calculated column look at the business days between those dates. I can calculate daysbetween with defined dates but I am unsure how I would use DAX with variable dates that are applied through Report filters.
I should also note I am not sure how best to handle a startdt and enddt filter based of the column, TheDate
Cheers!
Reference your dimdate table twice
StartDate = 'dimdate'
EndDate = 'dimdate'
and use this measure:
Num BusinessDays =
CALCULATE(
COUNTROWS('dimdate'),
'dimdate'[BusinessDay] = "Y",
'dimdate'[Date] >= SELECTEDVALUE(StartDate[Date]),
'dimdate'[Date] <= SELECTEDVALUE(EndDate[Date])
)

how do i write in sas a filter that subtracts dates

Hello Stackoverflow community... hope you can help with this sas question.
I need to create a filter for a table which gives back only those records that are active from last year forward.
I would like to obtain something like :
data want;
set have;
where expire_date >= current(date) - 1year:
run;
the format of the expire_date column is 03MAY2022 (date9. format)... I tried to transform the date into a number and then subtracting 365, but i guess there is a better solution.
can someone illuminate me?
thanks in advance
I think you are searching for the INTNX() function:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm#n1lchasgjah7ran0z2wlmsbfwdx2
For example:
data a;
format num_date num_date_minus_year DATE9.;
char_date="03MAY2022";
num_date = inputn (char_date, "DATE9.");
num_date_minus_year = intnx ('YEAR', num_date, -1, "SAME");
put num_date= num_date_minus_year=;
run;
Output:
num_date=03MAY2022 num_date_minus_year=03MAY2021
You can get the current date using the DATE() function.
Do you want one YEAR or 365 days?
To use a date interval use the INTNX() function.
where expire_date >= intnx('year',date(),-1,'same') ;
To use a fixed number of days just subtract the number.
where expire_date >= date() - 365 ;

SSRS exact month difference

This may have been asked before but I've not been able to find it having searched! In Oracle SQL there's a function called MONTHS_BETWEEN which returns a fractional value if the two dates you are comparing are not both the first day of the month for example. I need to do something similar in SSRS report builder, I've tried using DateDiff("m",Date1,Date2) however this always returns an integer and I think from what I can tell it just compares the two months from the dates, so when I compare 30/09/20 and 01/04/21 I get 7 months when actually it is much closer to 6.
Is there a function or a fix that can be used in SSRS to get that more accurate value?
Thank you!
For example I would like to get the following result:
Difference between 30/09/20 and 01/04/21 = 6.1
Difference between 01/08/20 and 30/09/20 = 1.9
It doesn't have to super accurate as I will be rounding to the nearest integer but I'm looking for something that will recognise that in the second example nearly 2 months have been covered and in the first example it's only just over 6 months.
If you only need an approximation then you could just calculate the number of days difference and divide by 30.
using the following expression...
=DATEDIFF("d", Fields!startDate.Value, Fields!endDate.Value)/30
I put a few more examples into a table and got the following results.
The following code mimics oracle definition of months_between
Public Function MonthsBetween( d1 As Date, d2 As Date) As Decimal
Dim df As Decimal
df = DateDiff("m", d1, d2)
If Day(d1) <> Date.DaysInMonth(Year(d1), Month(d1)) Or Day(d2) <> Date.DaysInMonth(Year(d2), Month(d2)) Then
df = df + Cdec((Day(d2)-Day(d1))/31)
End If
Return df
End Function
Integer result when both dates are last day of month
Negative result when date1 > date2
Decimal part based on 31 days month
For your expression use something like
=Code.MonthsBetween(Fields!date1.Value , Fields!date2.Value)
UPDATE
The following expression works in the same manner
= Cdec(
DateDiff("m", Fields!date1.Value, Fields!date2.Value)
+
Iif (
Day(Fields!date1.Value) <> Date.DaysInMonth(Year(Fields!date1.Value), Month(Fields!date1.Value)) Or
Day(Fields!date2.Value) <> Date.DaysInMonth(Year(Fields!date2.Value), Month(Fields!date2.Value)) ,
Cdec( (Day(Fields!date2.Value) - Day(Fields!date1.Value))/31),
0.0
)
)

Changing the values of Dates in SAS

Complete novice with SAS and I'm trying to convert a yearly range of dates to just "2014", "2015" & "2016." So for example I have an Orders column with a lots of dates in 2014, 2015 and 2016 and want to just convert the values in each year to just the name of the year. The code I was trying to use is below.
Data SortingDates;
set work.ClaraData;
if OrderDate <='31Dec2014'd then OrderDate = "2014";
if '01Jan2015'd <= OrderDate <= '31Dec2015'd then OrderDate= "2015";
if '01Jan2016'd <= OrderDate <= '31Dec2016'd then OrderDate = "2016";
run;
However this message comes: Character values have been converted to numeric values at the places given by...
Plus when printing the data, the dates all come out as 09/07/1965
The OrderDate column is properly formatted as "OrderDate Num 8 DDMMYY10. DDMMYY10."
Thanks!
You are getting the warning because you tried to assign the characters string "2014" to the numeric variable OrderDate. SAS probably successfully converted "2014" into 2,014 for you but since you didn't change the format it should display it as '07/07/1965' since that is the date that is 2,014 days since 01JAN1960.
It is probably easiest if you use the YEAR() function to get the year of a date value.
OrderYear = year(OrderDate);
But you could also just try using the YEAR. format on your existing OrderDate variable.
proc freq data=ClaraData ;
tables OrderDate ;
format OrderDate year. ;
run;
Try the year function (page 15 of this PDF): https://www.sas.com/storefront/aux/en/spfunctionxexample/62857_excerpt.pdf
Data SortingDates;
set work.ClaraData;
OrderDate = YEAR(OrderDate);
run;
Or keeping it as a date, try the year format (like page 8 of the same pdf)
Data SortingDates;
set work.ClaraData;
format OrderDate YEARw.;
run;

Classic ASP - Display all dates within a certain date range

I was wondering if i could get some help.
I have a little script that gets a date range based on a persons input.
It outputs the date range like so
6/7/2014
6/27/2014
What i need to do is output each date between these 2 dates.
Any help would be greatly appreciated.
Cheers
Dates in Classic ASP are fairly easy to use. Try this first: http://www.classicasp.aspfaq.com/date-time-routines-manipulation/could-i-get-a-little-help-with-dates.html
Here's a demo of looping through a series of sequential dates:
dim dcount, newdate
dcount = 0
newdate = startdate
do
response.write(newdate & "<br />")
newdate = newdate + 1
loop until newdate > stopdate
Obviously you'd need to specify startdate and stopdate, though this could be done as a sub or function.