I wonder if anyone could help on this please? I need to show the current month as a 2 digit field. IE
January as 01
February as 02
March as 03
etc until
October as 10
November as 11
December as 12
The formula I am using is: ToText ("0"& Month(CurrentDate))
but shows January as 01.00
ie need to remove the decimal point and the decimal places
Many thanks, Rob
Try this:
ToText( CurrentDate, "MM")
The ToText function will automatically convert the date you are supplying to whatever format you want. You don't need to use the Month function. Per the documentation, you just supply the date and the output format. For the month, you use "MM".
ToText(CurrentDate, "MM")
According to the documention, these are the valid strings you can use
Pattern Result
d Numeric day of month without leading zero (1, 7, 31)
dd Numeric day of month with leading zero (01, 07, 31)
ddd Three day abbreviation of day of week (Mon, Sat)
dddd Full name of day of week (Monday, Saturday)
M Numeric month without leading zero (1, 7, 12)
MM Numeric month with leading zero (01, 07, 12)
MMM Three letter abbreviation of month (Jan, Feb, Mar)
MMMM Full name of month (January, February, March)
yy Last two digits of year (11, 14, 22)
yyyy Full four digits of year (2011, 2014, 2022)
To add to the above, if you need to return something like Mar-17 then:
totext({Command.DocDate},"MMM") + '-' + totext({Command.DocDate},"yy")
Related
I have two variables called x and y. Each has 24*365 values. 24 presents the number of hours in a day and 365 presents the number of days in a year. I am plotting the values of 12th hour and 25th day by the following command:
plot(x(12:12,25), y(12:12,25))
Now I want to do the same for every 25th day for a whole year. Like 25th of Jan, 25th of Feb, 25th of March. I am not bothered about values of hours but I don't know how to create its logic as every month has different number of days.
You can generate the day of year number by getting the datenum values for the 25th of each month and subtracting the datenum of the 1st Jan that year.
dayIdx = datenum(2022,1:12,25) - datenum(2022,1,1) + 1;
Then just use this as your column index
plot(x(12,dayIdx), y(12,dayIdx))
The choice of 2022 above is arbitrary, as long as you pick a non-leapyear to get the 365-day year correct.
The datetime data type is awesome for this type of work.
%Make a vector of datetimes
ts = ( datetime(2001,1,1,0,0,0):hours(1):datetime(2001,12,31,023,0,0) )';
%Find the datetimes which are on the 25th day of the month, and the 12th
%hour of the day
mask = (day(ts) == 25) & (hour(ts) == 12) ;
%Confirm
ts(mask)
The result is below.
(You likely want to use the mask variable itself for your task. Sometimes you want to use find on the logical statement to get a list of indexes instead.)
ans =
12×1 datetime array
25-Jan-2001 12:00:00
25-Feb-2001 12:00:00
25-Mar-2001 12:00:00
25-Apr-2001 12:00:00
25-May-2001 12:00:00
25-Jun-2001 12:00:00
25-Jul-2001 12:00:00
25-Aug-2001 12:00:00
25-Sep-2001 12:00:00
25-Oct-2001 12:00:00
25-Nov-2001 12:00:00
25-Dec-2001 12:00:00
I'm trying to find out the weekday i.e Mon, Tue, Wed etc. from a date-range formatted as yyyy mm dd
I tried to use the formula format(day(Date Table),"ddd"), but the weekday is wrong. In my example, the output of 2020.01.01 gives Sunday, but it should be Wednesday.
I think your formula is wrong:
Instead of
format(day(Date Table),"ddd")
Use
format(<Target Table>[<date column>],"ddd")
I.e. Omit the DAX DAY call. This is resulting in the day of the month (1..31) being passed to the format function.
When you use the DAY function in DAX, it returns the day of the month (1 through 31).
Thus DAY ( DATE ( 2020, 1, 1) ) = 1 which means you're trying to format the number 1 as a date. Integers are interpreted as days since 1899/12/30 when treated as a date, so 1 corresponds to 1899/12/31, which happened to be a Sunday. Thus FORMAT(1, "ddd") = "Sun".
There's no reason to get DAY involved here. You can simply write
Day = FORMAT ( 'Calendar'[Date], "ddd" )
I'm trying to manipulate a date value to go back in time exactly 1 ISO-8601 year.
The following does not work, but best describes what I want to accomplish:
date_add(date '2018-01-03', interval -1 isoyear)
I tried string conversion as an intermediate step, but that doesn't work either:
select parse_date('%G%V%u',safe_cast(safe_cast(format_date('%G%V%u',date '2018-01-03') as int64)-1000 as string))
The error provided for the last one is "Failed to parse input string "2017013"". I don't understand why, this should always resolve to a unique date value.
Is there another way in which I can subtract an ISO year from a date?
This gives the corresponding day of the previous ISO year by subtracting the appropriate number of weeks from the date. I based the calculation on the description of weeks per year from the Wikipedia page:
CREATE TEMP FUNCTION IsLongYear(d DATE) AS (
-- Year starting on Thursday
EXTRACT(DAYOFWEEK FROM DATE_TRUNC(d, YEAR)) = 5 OR
-- Leap year starting on Wednesday
(EXTRACT(DAY FROM DATE_ADD(DATE(EXTRACT(YEAR FROM d), 2, 28), INTERVAL 1 DAY)) = 29
AND EXTRACT(DAYOFWEEK FROM DATE_TRUNC(d, YEAR)) = 4)
);
CREATE TEMP FUNCTION PreviousIsoYear(d DATE) AS (
DATE_SUB(d, INTERVAL IF(IsLongYear(d), 53, 52) WEEK)
);
SELECT PreviousIsoYear('2018-01-03');
This returns 2017-01-04, which is the third day of the 2017 ISO year. 2018-01-03 is the third day of the 2018 ISO year.
LibreOffice Calc spreadsheet offers a function ISOWEEKNUM to return the standard ISO 8601 week number of the specified date.
I want the opposite.
➠ Given a standard week number, give me the date of the first day of that week (the Monday date).
Passing integers is acceptable. Also nice if able to pass a string in standard format.
Like this:
DATE_OF_ISOWEEKNUM( 2017 , 42 ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( "2017-W42" ) ➝ date of Monday of week 42 in week-based year 2017
Ideally, I would be able to pass a number 1-7 for Monday-Sunday to specify the day-of-week for which I want a date. Something like this:
DATE_OF_ISOWEEKNUM( 2017 , 42 , 1 ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( "2017-W42-1" ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( 2017 , 42 , 7 ) ➝ as above, but Sunday
DATE_OF_ISOWEEKNUM( "2017-W42-7" ) ➝ as above, but Sunday
Example:
Formula:
=DATE(B$1,1,$A4*7)+(2-WEEKDAY(DATE(B$1,1,$A4*7)))-7*(ISOWEEKNUM(DATE(B$1,1,1))=1)
Calculate the date of day (weeknumber * 7) in the year.
Correct the day to be weekday Monday.
Correct to 7 days before, if the first day of the year is in the
first ISO weeknumber.
I'm using Zend_Date to set and get the year, but it is not being set as the correct year. I set the year as 2010, and it returns the year as 2009. What am I doing wrong? Is there a bug in Zend_Date?
$date = new Zend_Date('2010-01-03', 'YYYY-MM-dd');
echo $date->toString('MMMM d, YYYY');
//outputs January 3, 2009
The year must be being set correctly because getting the year part of the date works:
echo $date->get(Zend_Date::YEAR); //2010
Solution:
Well I got it to work...You have you use lowercase: yyyy
echo $date->toString('MMMM d, yyyy');
YYYY stands for the ISO Year. 2010-01-03 is week 53, day 7 of the ISO year 2009
yyyy stands for the actual calendar year.
I've ran into this problem as well.
In the Zend_Date class 'YYYY' means to a 4 digit representation of the 'ISO year' where as 'yyyy' means a 4 digit representation of the 'year'.