I would like to display a date like...
=Now.ToLongDateString()
BUT without the weekday. So the expression would produce June 21 2011. Not Tuesday, June 21 2011. Is this possible? I don't want the format MM/DD/YY. I would rather have June 21 2011.
I have found an expression that works. This is here for others to use.
=FORMAT(Now,"MMMM dd, yyyy")
I don't like answering my own questions because most here think its a reputation point thing (which its not) SO, If anyone else provides an answer that is more helpful or is "neater", I will toggle off my checkmark and mark yours. Otherwise, I'll leave this up so others can use the answer as per Meta.
Related
Can anyone tell me why if I type in MATLAB
datestr('17-03-2016','dd-mmmm-yyyy')
I get
06-September-0022
From the datestr docs
DateString = datestr(___,formatOut) specifies the format of the output text using formatOut. You can use formatOut with any of the input arguments in the above syntaxes.
So in your example the 'dd-mmmm-yyyy' is specifying the output format, not the input format.
Also
DateString = datestr(DateStringIn) converts DateStringIn to text in the format, day-month-year hour:minute:second. All dates and times represented in DateStringIn must have the same format.
where
'dd-mm-yyyy' is not in the list of allowed DateStringIn formats AND the documentation explicitly recommends using datenum to ensure correct behaviour. (Note: I underlined the wrong must in the sentence, it's the second must I wanted to emphasise)
So Sandar_Usama's answer of
datestr(datenum('17-03-2016','dd-mmmm-yyyy'))
is the officially correct method straight out of the docs.
Bottom line, always read the documentation.
Use this instead: datestr(datenum('17-03-2016','dd-mmmm-yyyy'))
To address the last unanswered point in this question, why does datenum behave like this?
>> datestr(datenum('17-03-2016'))
ans =
06-Sep-0022
Without explicitly telling datestr and datenum how it should treat the input, it will try to match against the expected formats. Since none of the documented formats match (see #dan's answer), it fails.
Although what it does next is undocumented, at least up to whatever version of Matlab we are running, it falls into a "last resource" attempt to give you a date number.
Matlab will try to parse different month names from your input, remove non-numeric characters, and then timedate elements from the string. In your case, they are 17, 03, and 2016. The first is expected to be either month or year. Since there's no 17th month, it is treated as year. Then 03 is the month, and 2016 is the day.
Now, March 2016th, 17 is not a valid date, but Matlab will give it a slack and read as 1985 days past March 31st, 17. And that gives us September 6th, 22.
Because Matlab's timestamp is a floating number for the number of days since its epoch, you can trigger that answer, using valid dates, like so:
>> datestr(datenum('0017-03-31') + 1985)
ans =
06-Sep-0022
I like creating headings that look like
** WW47 (Monday November 18 - Sunday November 24, 2013)
I know how to use format-time-string, etc., in emacs/elisp to determine various definitions of the week-number (%U, %V, %W).
Q: how can I go backwards? In emacs/elisp, determine the dates of the first and last days of the week, given a year and week number?
More generally, parse a time-string such as ISO 8601 week-dates 2006-W52-7, or the week without day within week 2013-W46.
More generally still - many date and time representations imply date intervals. Weeks and months in particular imply intervals, although I suppose almost any time representation of a given precision can be interpreted as corresponding to an interval of time units less than the precision.
Q: are there (reasonably standard) emacs/elisp functions for determining first and last dates of a month, e.g. in terms of year/day-of-year format? Etc.
--
This post is mainly a "how do I do this in emacs/elisp?" question.
This sort of question appears to be quire common - there are similar questions on stackoverflow asking "how do I do this in Javascript/C#/..." etc., etc., etc.
I can do the math myself. But (a) better if there is a standard emacs/elisp function to do this, and (b) it is apparent from googling that there are many gotchas and issues, further emphasizing the goodness of using a standard library function, if one exists.
E.g. Getting first date in week given a year and weeknumber
I had a similar problem (see https://emacs.stackexchange.com/questions/43984/convert-between-iso-week-and-a-normal-date).
Using my solution on https://emacs.stackexchange.com/questions/43984/convert-between-iso-week-and-a-normal-date, the solution to your first question is found below.
Example:
(iso-header 2018 32)
"** WW32 (Monday August 06 - Sunday August 12, 2018)"
(iso-header 2018 53)
"** WW01 (Monday December 31 - Sunday January 06, 2019)"
(defun iso-header(year week)
(concat
(format-time-string "** WW%V (%A %B %d - " (iso-beginning-of-week year week))
(format-time-string "%A %B %d, %Y)" (iso-end-of-week year week))))
I've read a many things about parsing date in obj-c, but I can't find anything dealing with dates like "Mon, 25 Apr 2011 11:53 am CDT"... I'd like to convert it to NSDate in a smart way but I'm running out of ideas.
Thanks.
-[NSDateFormatter dateFromString:]
You'd probably use #"EEE, d MMM yyyy hh:mm a zzz" as your date format string.
And by the way, googling "convert string to date objective-c" yields thousands of hits that have correct answers.
NSDateFormatter is a pretty complete class that covers all "human-friendly" date scenarios.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html
There's also several questions on stackoverflow that seem very similar to your question, so a quick search should help you out.
I have a very strange problem, Zend_Date is converting my timestamp to a year earlier.
In my action:
// Timestamp
$intTime = 1293922800;
// Zend_Date object
$objZendDate = new Zend_Date($intTime);
// Get date
echo date('Y-m-d',$intTime).'<br>';
echo $objZendDate->get('YYYY-MM-dd');
This outputs:
2011-01-02
2010-01-02
Can anyone tell me what i'm doing wrong?
From the ZF issue tracker it seems this is a known issue:
Recently a lot of ZF users are filing a bug that Zend_Date returns the wrong year, 2009 instead of 2008. This is however expected behaviour, and NOT A BUG!
From the FAQ:
When using own formats in your code you could come to a situation where you get for example 29.12.2009, but you expected to get 29.12.2008.
There is one year difference: 2009 instead of 2008. You should use the lower cased year constant. See this example:
$date->toString('dd.MM.yyyy');
instead of
$date->toString('dd.MM.YYYY');
From the manual
Note that the default ISO format differs from PHP's format which can be irritating if you have not used in previous. Especially the format specifiers for Year and Minute are often not used in the intended way.
For year there are two specifiers available which are often mistaken. The Y specifier for the ISO year and the y specifier for the real year. The difference is small but significant. Y calculates the ISO year, which is often used for calendar formats. See for example the 31. December 2007. The real year is 2007, but it is the first day of the first week in the week 1 of the year 2008. So, if you are using 'dd.MM.yyyy' you will get '31.December.2007' but if you use 'dd.MM.YYYY' you will get '31.December.2008'. As you see this is no bug but a expected behaviour depending on the used specifiers.
For minute the difference is not so big. ISO uses the specifier m for the minute, unlike PHP which uses i. So if you are getting no minute in your format check if you have used the right specifier.
To add to zwip's answer, what happens behind the scenes is that your date format YYYY-MM-dd is actually translated into o\-m\-d, which is then passed to PHP's date() function internally with the timestamp you provided.
Like mentioned in the other answer, and in the documentation for the o format on the date format page, the calculation of the year based on the ISO week can sometimes result in the year being one different to the value that you expect.
I'm successfully setting a date-picker with an initial date from a plist, but I see some unwanted blue values in the month, day, and year components, presumably corresponding to current date. So if today is April 18, 2010 and initial date being set is March 19, 2008, it looks like this (bold represents the blue):
January 17 2006
February 18 2007
------------------------------
March 19 2008
------------------------------
April 20 2009
May 21 2010
First question is: How do I get rid of the blue?
And second question: Ideally, how do I get it to look like this?
January 17 2006
February 18 2007
------------------------------
March 19 2008
------------------------------
April 20 2009
May 21 2010
Third question, totally unrelated and not as important: How could I have gotten the above to show in blue rather than bold? I see blue in code snippets all the time.
Matt
Sadly, I do not believe it's possible to suppress the coloring of the current date components in blue. You could always file a feature request for this functionality.
As a last resort, you could implement your own (or Google for "generic date picker" - someone has already done this).
I think the code sample formatter automagically makes things blue that it thinks are keywords, like:
UIDatePicker* myPicker;
I didn't tell it to make that blue, it just is.