Want to convert NSDateFormatter with suffixes to a NSdate - nsdateformatter

I have a string with date 1st Junuary 2012 or 22nd September 2011 or 3rd July 2011 or 14th October 2011. I need to convert this date with nd,st,th and rd suffixes to a specific date i.e dd-mm-yyyy. Can anyone guide me with this. What is the dateformatter for this kind of dates (22nd July 2011). Any help will be great.

Related

Sorting Month And Year Results In Microsoft Access

I have the following table in Microsoft Access
TransactionDate
Market
Details
Opening
Closing
Size
Profit/Loss
I want to run a query that shows the Profit/Loss for each month.
I have been able get a query that returns the information in the following format
TransactionDate By Month Sum Of Sum Of Profit/Loss
April 2014 €1,084.99
April 2015 €674.33
April 2016 €2,057.30
August 2014 €237.59
August 2015 -€267.82
December 2014 €375.88
December 2015 -€1,161.97
February 2015 -€603.87
February 2016 -€124.71
January 2015 €75.11
January 2016 -€1,044.35
But what I want now is for it to display in chronological order as oppose to Alphabetical order.
For example
January 2014
February 2014
March 2014
etc.
I will consider that your TransactionDate field is defined as String
If you want to order by this text field in Access, you will have to use DateValue() function.
That would give:
SELECT TransactionDate FROM yourTable ORDER BY DateValue(TransactionDate)
If your field is already formatted as a Date field, then simply use order by TransactionDate to make it work.

Powerpivot: year to date vs year to date previous year

I am using excel 2013 powerpivot which I have linked to a sql query. In this query I have all sales data from previous years and it updates itself with the current sales. I want to make a pivottable showing year to date sales from this year compared to the same period last year. So for example from Jan.1st 2015 until July 10th of 2015 compared to Jan.1st 2014 until July 10th 2014.
I linked my sales data table with a calendar table. But whatever I try, parallelperiod, sameperiodlastyear, totalytd, it always shows me the correct data for this year, but the full year sales of last year. Can anyone recommend me what to try?
thanks,
Frank
The TOTALYTD (and other time intelligence functions) will look for the highest date in whichever context you give it, so when you try to tell it to go back 12 months from now it thinks "OK, I'm in 2014" I'll get ALL the data from 2014 and calculate a TOTALYTD. So you have to ignore the built-in functions and build your own:
=CALCULATE(sum(Table1[sales]),DATESBETWEEN(DateDim[Date], FIRSTDATE(DATEADD(DateDim[Date],-12,MONTH)), LASTDATE(DATEADD(Table1[Date],-12,MONTH))))
So long as you have a slicer or a field on your table that picks up the year, then that should work.
Edit: Having tested with a data sample, again DAX is trying to be too clever and because I have told it to go back 12 MONTHS, it assumes I want ALL data from the month context which is including everything from July last year.
Going back 365 days fixes this (as long as it's not a problem for leap years).
=CALCULATE(sum(Table1[sales]),DATESBETWEEN(DateDim[Date], FIRSTDATE(DATEADD(DateDim[Date],-12,MONTH)), LASTDATE(DATEADD(Table1[Date],-365,DAY))))
I have tried your way, but it does not yet give me the correct answer. Let me show you what I have right now.
For current year sale I have the following Dax formula
=TOTALYTD(sum(Omzetgegevens[NettoOmzet]); Kalender[Calender date])
For the previous year sale I have:
=CALCULATE((SUM(Omzetgegevens[NettoOmzet])); SAMEPERIODLASTYEAR(DATESYTD(Kalender[Calender date])))
To test your solution I have called "test ytd":
=CALCULATE(SUM(Omzetgegevens[NettoOmzet]); DATESBETWEEN(Kalender[Calender date]; FIRSTDATE(DATEADD(Kalender[Calender date];-12; MONTH)); LASTDATE(DATEADD(Kalender[Calender date]; -365; DAY))))
If I run the pivottable now, the result I get is:
2015
current year ytd last year ytd test ytd
januari 28.912 34.487 34.487
februari 50.301 66.003 31.516
maart 73.362 92.647 26.644
april 99.561 117.853 25.205
mei 128.021 149.108 31.255
juni 149.706 174.076 24.968
juli 158.297 205.438 31.362
augustus 158.297 231.693 26.255
september 158.297 254.534 22.841
oktober 158.297 282.484 27.951
november 158.297 303.808 21.324
december 158.297 313.208 9.400
Total 158.297 313.208 313.208
What I would like to see is the following. As this report was run on the 14th of july 2015. I want to see all sales for 2015 until this date and all the sales for 2014 until july 14th 2014.
If it is not possible to see the months, I am also fine with only a total number for current ytd and last year ytd
2015
current year ytd last year ytd
januari 28.912 34.487
februari 50.301 66.003
maart 73.362 92.647
april 99.561 117.853
mei 128.021 149.108
juni 149.706 174.076
juli 158.297 175.312(so not full month of july in 2014)
Total 158.297 175.312
Recently had a similar issue. Current context confuse a lot and did not return the result we think should be returned. Play with DATEADD to go back and forth in combination with any of the date/time function. You will get the result and the context will also be clear.

nsdate format to last digit in year, then day of year

The following code will output this (current day is Jan 15, 2015):
2015015
I need it to output this:
5015
I want it in the format of yddd, where y is the last number in the year, and ddd is the day of the year. so January 1st, 2000 is 0001 and December 31st, 2007 is 7365.
NSDate *julianLabel = [NDDate date];
NSDateFormatter *julianFormatter = [[NSDateFormatter alloc] init];
[julianFormatter setDateFormat:#"yddd"];
self.julian.text = [julianFormatter stringFromDate:julianLabel];
Surely you could just use substringFromIndex on the string, something that should work for the next eight thousand years or so (a). In other words, something like:
self.julian.text = [[julianFormatter stringFromDate:julianLabel] substringFromIndex:3];
(a) It'll work as per your specification until we reach the year 10,000 but keep in mind you'll start getting duplicates in 2025. I'm assuming that's not a problem due to the detail provided.

NSDateFormatter show wrong year

im using xcode 4.5(4G182) with iOS 6. NSDateFormatter show wrong year in iOS 6, how to solve?
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:#"YYYY-MM-dd"];
NSString *str = [dateFormatter stringFromDate:[NSDate date]];
NSLog(#"%# == %#",str,[[dateFormatter dateFromString:str] description]);
it print out "2012-09-14 == 2011-09-13 16:00:00 +0000"
YYYY is not the same as yyyy.
According to this page which the iOS Date format page references;
`y`: Year
`Y`: Year (in "Week of Year" based calendars). This year designation is used in
ISO year-week calendar as defined by ISO 8601, but can be used in
non-Gregorian based calendar systems where week date processing is desired.
May not always be the same value as calendar year.
The operative sentence being the last one. Use yyyyinstead.
Further details on how and why the year values may deviate when using YYYY:
The ISO week-numbering year starts at the first day (Monday) of week
01 and ends at the Sunday before the new ISO year (hence without
overlap or gap). It consists of 52 or 53 full weeks. The ISO
week-numbering year number deviates from the number of the traditional
Gregorian calendar year on a Friday, Saturday, and Sunday, or a
Saturday and Sunday, or just a Sunday, at the start of the traditional
Gregorian calendar year (which are at the end of the previous ISO
week-numbering year) and a Monday, Tuesday and Wednesday, or a Monday
and Tuesday, or just a Monday, at the end of the traditional Gregorian
calendar year (which are in week 01 of the next ISO week-numbering
year). For Thursdays, the ISO week-numbering year number is always
equal to the traditional Gregorian calendar year number.
Examples:
Monday 29 December 2008 is written "2009-W01-1"
Sunday 3 January 2010 is written "2009-W53-7"
From https://en.wikipedia.org/wiki/ISO_8601#Week_dates
(bold styling added)

NSDateFormatter "w"

In my app, I used "w" to format date:
With "w", does a new week start on Sundays?
The date is local right?
NSDateFormatter will use your location settings (See NSLocal).
So If canadian is your local and canadian calendars starts on Saturday this is your week.
For your question about the week element,
The following is from HERE, your NSDateFormatter uses the ISO Standard.
Week date is an alternative date representation used in many
commercial and industrial applications. It is: YYYY-Www-D
where YYYY is the Year in the Gregorian calendar, ww is the week of
the year between 01 (the first week) and 52 or 53 (the last week), and
D is the day in the week between 1 (Monday) and 7 (Sunday).
Example: 2003-W14-2 represents the second day of the fourteenth week
of 2003.
This means that for the Gregorian calendar, the weeks start on Mondays.
In additions to PascalTurbo's post, if you need to, you can explicitly set set the timezone for your date formatter like the following example:
NSDateFormatter *dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:#"GMT"];