Is it possible to get a long date in the current locale? - c

I can pass the result of nl_langinfo(D_FMT) to strftime to get a date string formatted according to the rules of the currently active locale. This works fine but it only allows me to get a short date, e.g. 21.01.2023 for January 21st, 2023 on a German system. On Windows I can also query LOCALE_SLONGDATE to get a long date, which would be something like Samstag, 21. Januar 2023 for January 21st, 2023 on a German system.
Is there any way to get such long date strings formatted according to the rules of the current locale on Linux?

Related

Get week number based on ISO8601

Is there any way in SQL Server to get week number based on specific date which would reflect
according to ISO8601 where Monday is the first day of week?
Just use the aptly named ISO_WEEK Datepart:
iso_week datepart
ISO 8601 includes the ISO week-date system, a numbering system for weeks. Each week is associated with the year in which Thursday occurs. For example, week 1 of 2004 (2004W01) covered Monday, 29 December 2003 to Sunday, 4 January 2004. European countries / regions typically use this style of numbering. Non-European countries / regions typically do not use it.
SELECT DATEPART(ISO_WEEK,YourDate)
FROM dbo.YourTable;

Display Month in Spanish using strftime?

I am trying to get the format a date from 2018-09-01 to September 1, 2018.
I have been using:
strftime(displayDate, sizeof(displayDate), "%B %d %Y", &date_obj);
It works perfectly, but, is there a way to format the Month to be in Spanish?
The strftime function formats dates based on the current locale. So you'll need to set the locale for LC_TIME first:
setlocale(LC_TIME, "es_ES-UTF_8");
See setlocale for more information.

Date time not formating in AngularJs 1.6

I've got this format of date coming from an api:
"dateTime": "2018-02-19 00:00:00.000-08:00"
I just want the days, month and year in the format: dd/MM/yyyy
I'm using this in the view:
<td>{{dado.dateTime | date:'dd/MM/yyyy'}}</td>
But it's shows the date extacly as it comes from the API. Without any formatting
OBS: Angular 1.6
You are missing the T in your original DateTime. For ISO8601 DateTime it should be "2018-02-19T00:00:00.000-08:00" as the value. That is what can be translated by the angular date filter as a DateTime, currently it can only be interpreted as a string.
From the documentation on the input:
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
If you do not have any control over the server/source then you have a couple of options:
Change the value of the date time string in the factory/service when you receive the data so it is ISO8601 compliant. This can be as simple as using a regex or string concatenation as long as the T character is added between the date and time. In this specific case you could take the first 10 characters as you probably want to completely ignore the time portion but that would not work where you do want to show or keep time as a part of the datetime.
Create your own filter that then calls through to the built in date filter once you format the input correctly.

Angular localization problems with number and date format

I am trying to format a date based on localisation and have the locale files setup correct so when using date format of shortDate I get the difference between UK and US format.
However we need the date to show the full year 2016 and not 16.
If I code it as dd MM yyyy then that gives me the correct UK format but when toggling to US mode the filter keeps it in that dd MM yyyy format.
How can I enable the date to be of type day month year for UK and month day year for US etc ?
Try https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
// US English uses month-day-year order
console.log(date.toLocaleDateString('en-US'));
// → "12/19/2012"
// British English uses day-month-year order
console.log(date.toLocaleDateString('en-GB'));
// → "20/12/2012"
Note this is not IE friendly like most of html5 and ES6 :v.
other way is to use http://momentjs.com/

Convert String to datetime in SQL Server 2008

How will I convert date in the format Sat Mar 29 00:00:00 EST 1975 to datetime in TSQL?
I get the date in this format from an old table which defined the date of birth column as NVARCHAR and stores the data as Mon Jun dd hh:mm:ss GMT yyyy format. I need to read another table which has the dob in datetime using this value.
So basically I want to convert, say Sat Mar 29 00:00:00 EST 1975 to 1975-03-29 00:00:00.000
Is there a way in T-SQL to do this conversion? I tried the CONVERT function, but I am unable to locate the correct 'style' to use.
Examining the data format, it appears to be a fixed length string.
The first portion is the day of week, which can be discarded as it isn't needed for parsing. Next you have the month and day information, which we need. After that is the time, which can be retained or discarded depending on whether you want a date or datetime as output.
Since you are looking for a date of birth, the time zone information can most likely be safely discarded.
Finally, there is the year.
If we eliminate the day of week and the time zone, sql server will parse the rest of the string with no problem.
I recommend cast(substring(#difficultTime,5,7) + substring(#difficultTime,25,4) as date), where #difficulteTime is the column name you are converting.
If you wanted to retain the time information, the following format will work cast(substring(#difficultTime,5,16) + substring(#difficultTime,25,4) as datetime)
This assumes that your strings will be of a fixed length. The first conversion shown eliminates the day of week, the time, and the time zone from the string, leaving a parseable date.
The second conversion eliminates the day of week and the time zone, leaving a parseable datetime.

Resources