How to format a date string like '2018-08-31' - typo3

I've got a date-string like '2018-08-31' from tt_content and want to convert it like this: '31 August 2018' - how do I get this to work?
I've tried this:
10 = TEXT
10 {
wrap = |
data.field = tx_mask_cnt_news_item_date // field in tt_content, is '2018-08-31'
strftime = %e %B %Y
}
But this puts out the current date (in the desired format). Can somebody give me a hint?

Try this:
10 = TEXT
10 {
wrap = |
field = tx_mask_cnt_news_item_date
strftime = %e %B %Y
}
data.field = tx_mask_cnt_news_item_date will set the content of tx_mask_cnt_news_item_date as the value for data, which will result in nothing. field directly in the TEXT object will set the content of tx_mask_cnt_news_item_date as the value of the TEXT object, which will then be passed through strftime.

I've found a solution: With strtotime = 1 the string will be converted into a timestamp and then strftime will work as expected:
10 = TEXT
10 {
wrap = |
field = tx_mask_cnt_news_item_date // field in tt_content, is '2018-08-31'
strtotime = 1
strftime = %e %B %Y
}

Related

How to reverse convert InputFormat of datetime constructor in Matlab?

How to reverse convert InputFormat of datetime constructor in Matlab?
datestr doesn't work:
>> startTime = datetime('2014/06/01-00:00', 'InputFormat', 'yyyy/MM/dd-HH:mm')
startTime =
datetime
01-Jun-2014 00:00:00
>> datestr(startTime, 'yyyy/MM/dd-HH:mm')
ans =
2014/00/01-00:06
As you see, it turns months into minutes.
How to overcome?
UPDATE
Format should not be hardcoded, solution should work in both ways with one given format string.
Set the 'Format' of your datetime object to the desired output and use char():
tfmt = 'yyyy/MM/dd-HH:mm';
startTime = datetime('2014/06/01-00:00', 'InputFormat', tfmt, 'Format', tfmt);
char(startTime)
Which returns:
>> SOcode
ans =
'2014/06/01-00:00'
Note that this is a documented limitation of datestr
Note
The symbolic identifiers describing date and time formats are different from those that describe the display formats of datetime arrays.
Rearranging the out format (very small change) of datestr worked:
startTime = datetime('2014/06/01-00:00', 'InputFormat', 'yyyy/MM/dd-HH:mm')
startTime =
01-Jun-2014 00:00:00
datestr(startTime, 'yyyy/mm/dd-HH:MM')
ans =
2014/06/01-00:00

CakePHP 3 - Comparing and modifying dates

In the CakePHP 3 Cookbook on Date/Time, you can compare time intervals with future/past days/weeks using IsWithinNext/WasWithinNext. You can also modify dates/times by doing a ->modify('extra time') - eg. if $date = 2016-01-01, $date->modify('+1 week') would mean $date = 2016-01-08.
These features require the use of Cake\i18n\Time. However, when I attempted to use these features, I received a Cake error:
Call to a member function isWithinNext() on string.
This is the code I used:
$date_start = \Cake\Database\Type::build('date')->marshal($data['session']['date_start'])->i18nFormat(); //before hand my dates were in the form of an array comprised of Year, Month and Day. This changes them into date format.
if($date_start->isWithinNext('1 week')){
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+48 hours');
} elseif ($date_start->isWithinNext('2 weeks')){
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+1 week');
} elseif ($date_start->isWithinNext('3 weeks')){
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+1 week');
} else {
$deposit_due = $booking->date_confirm;
$deposit_due->modify('+2 weeks');
}
Calling i18nFormat() returns a formatted string as you can look up in the API: https://api.cakephp.org/3.4/class-Cake.I18n.DateFormatTrait.html#_i18nFormat
This, for example, should work:
$date_start = new \Cake\I18n\Time($data['session']['date_start']);
debug($date_start->isWithinNext('2 weeks'));

How to add string to date function - Progress 4gl

I am newbie in Progress and I've Trouble in date function Progress 4gl.
Example I have string value = '2016 '.
How do I put that value into a date in Progress?
Example:
def var xx as char.
def var xq as date.
ASSIGN
xx = '2016'
xq = DATE(01/01/xx).
While it is possible to write
ASSIGN
xx = '2016':U
xq = DATE('01/01/':U + xx)
.
I would prefer
ASSIGN
xx = '2016':U
xq = DATE(1,1,integer(xx))
.
(The first example is dependent on the current date format. If you look up the DATE function in the OpenEdge Help you can see that DATE ( month, day, year ) is valid, too.)

GWT DateTimeFormat returns the wrong date

I have the following code
String test = "21/04/2013";
fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
Date dateTest = fmt.parse(test);
Window.alert(fmt.format(dateTest));
And the alert box shows the date
09/04/2014
instead of
21/04/2013
Why?
As others already say, it's because of your pattern. What they don't say is why it behaves that way.
When parsing 21/04/2013 as MM/dd/yyyy, DateTimeFormat will decompose the date as:
Month Day of month Year
21 4 2013
and it'll then adjust things to make a valid date. To do that, the Month part is truncated at 12 (so that temporary date is Dec 4th, 2013) and the remainder (21 - 12 = 9) is then added, leading to Sept. 4th 2014, which according to your format displays as 09/04/2014.
You wanted to show 21/04/2013 but the format was MM/dd/yyyy.
It should be dd/MM/yyyy
So change it like this:
String test = "21/04/2013";
fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
Date dateTest = fmt.parse(test);
Window.alert(fmt.format(dateTest));
You're reversing day and month.
String test = "21/04/2013";
fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
Date dateTest = fmt.parse(test);
Window.alert(fmt.format(dateTest));

Get date from Unix Timestamp in Metro style App

Iam reading out a Json file with a date in it.
jsonValue->GetObject()->GetNamedObject("board")->GetNamedNumber("date")
That date is saved in Unix code format:
"date":1347973494
But I need to get it in a normal format like "19.09.2012".
I cant find the right function to solve that problem.
I already tried the DateTimeFormatter class but I think that was not the correct way to make this.
So anyone knows how to change the DateTime from Unix timestamp to a normal format like "19.09.2012"?
A Unix timestamp is seconds since 1970, so add the seconds to 1970-01-01.
int unixTimestamp = 1347973494;
System::DateTime timestamp = System::DateTime(1970, 1, 1).AddSeconds(unixTimestamp);
Then format the DateTime into whatever string format you like, or use it as a DateTime.
System::String^ formatted = timestamp.ToString("dd.MM.yyyy")
I solved the problem with the Calendar class which you can find here
int unixTimestamp = (int)jsonValue->GetObject()->GetNamedNumber("date");
Windows::Globalization::Calendar^ cal = ref new Windows::Globalization::Calendar();
cal->Year = 1970;
cal->Month = 1;
cal->Day = 1;
cal->Minute = 0;
cal->Hour = 0;
cal->Second = 0;
cal->AddSeconds(unixTimestamp);
mainDate -> Text = cal->DayAsString() + ". " + cal->MonthAsString() + " " + cal->YearAsString();