HI all,
I got a JavaScript function to convert the date, but I was wondering if there is any way to convert the date with xsl without using JavaScript.
Thanks.
and the string manipulation, http://www.xml.com/pub/a/2002/05/01/xslt-string.html
Thanks to all of you for answering my question, after looking on those links you left me to take a look I came out with something very simple.
<xsl:for-each select="//MaternityDiaryEvent/DateOfVisit">
<xsl:value-of select="concat(substring(.,9,2),'/',substring(.,6,2),'/',substring(.,3,2))"/>
</xsl:for-each>
Thanks again to all, I'll give you a vote to each of you.
Cesar.
The format-date function might do the job.
You can use the Microsoft formatter.
Or the format-date function, if you are using XSLT 2.0 (which .Net does not).
Found a very good post on date formatting here.
No Javascript required.
Only XSL elements and XPath String functions can do the job.
Related
in TYPO3 8 LTS i try build a json output from news list. When using the viewhelper f:format.json in exact the same way as in the fluid manual:
{f:format.json(value: {foo: 'bar', bar: 'baz'})}
i get this:
{"foo":"bar","bar":"baz"}
this works:
{f:format.json(value: newsItem.datetime)->f:format.htmlentitiesDecode()}
but i need the date-object formatted in this way:
{newsItem.datetime->f:format.date(format: "%Y-%m-%d")}
and now i am looking for a possibility to match both in order to get this output:
{'date':'2018-03-16'}
I tried a many ways like this, but nothing works.
{f:format.json(value: {date:newsItem.datetime->f:format.date(format: "%Y-%m-%d")})->f:format.htmlentitiesDecode()}
any idea how to get it right?
Thanks
Peter
well Bernd showed me the way in his comment above - here is one of the solutions which i found with this little help of him:
{f:format.json(value: {date:'{newsItem.datetime->f:format.date(format: "%Y-%m-%d")}'})->f:format.htmlentitiesDecode()}
f:format.raw works much the same like f:format.htmlentitiesDecode; really important are the two '' around {newsItem.datetime->f:format.date(format: "%Y-%m-%d")}.
With the idea of format.raw i found an other solution too:
<f:format.raw value='{"date":"' />{newsItem.datetime->f:format.date(format: "%Y-%m-%d")}<f:format.raw value='"},' />
Looks quite a bit complicated but with
<f:format.raw value='{' />
<f:format.raw value='}' />
it is possible to use curly brackets in fluid templates.
Thanks!
Output: 2015-01-20 03:52:19
Need 01.20.2015 + 1 week = 01.27.2015
I curently have {$order[orders].invoice_date|date_format:"%d.%m.%Y"}
But how to add week + 1?
So, I need to add 1 week and then formating this.
But the date isn't in the timestap format.
Smarty version: 3.1.
I can use only smarty logic, not PHP.
How to achieve this?
You don't need a plugin to work this out. It can be solved with a combination of cat and date_format.
Since date_format is a wrapper to PHPs strftime(), you can use the conversion specifiers available in strftime() - and that is what I used tackle the issue at hand.
Try this:
{$order[orders].invoice_date|cat:' +1 week'|date_format:"%d.%m.%Y"}
I've used Smarty version 3.1.17 to recreate your problem. The solution is based on the assumption that the value in your variable $order[orders].invoice_date is a string 2015-01-20 03:52:19.
You can create a smarty plugin, something like this one to suit your needs. http://smarty.incutio.com/?page=AlternativeDateModifierPlugin
You shouldn't be doing this logic in smarty at all. This type of thing should be done in the php code - assign two date values to two separate smarty variables (one with the 1 week added), and use the appropriate one in the appropriate place in your template (applying the appropriate date_format as required).
edit: I know you've said you want to do this using smarty syntax - I'm just pointing out that trying to do this type of manipulation in smarty is not what the template language is designed for. If you only have access to the smarty .tpl files, you might try using the {php} tag to put your php logic in the .tpl file.
I have a problem where I want to compare two dates or in other words I want to find the difference of two dates in JSP using JSTL.
I have seen many solutions like creating a JSP:bean of Date object. Other ones were more messy solutions.
Can anybody please provide me a cleaner solution so that I can do this with JSTL only? I need a solution somewhat like SQL DATEDIFF function in JSTL
Thanks in advance.
Just use <fmt:formatDate> to extract the year from it so that you can do the math on it.
Edit : Ihen use two varibles to store both dates
<fmt:formatDate value="${date1}" pattern="yyyy" var="Date1" />
<fmt:formatDate value="${date2}" pattern="yyyy" var="Date2" />
<c:if test="${Date1 le Date2}">
<doSomeLogic/>
</c:if>
Is there a way to display a date in an input different from the format I want to submit.
For example I have to submit a date in "yyyy-mm-dd" format but I want to display the date in another format : "dd/mm/yyyy" (french display).
Is there a good tip to do that with Datebox for jQuery Mobile (an option I didn't see ?)
I think I have to cheat in creating an input hidden with the good form format and another one with the format to display (and not submitted), but maybe a better solution exists.
Any ideas ?
Your best bet is to indeed use 2 inputs - but, it's pretty easy to do, and using a callback on the set event, you can even make datebox do the second format for you.
http://dev.jtsage.com/jQM-DateBox2/demos/script/split.html
(Note: I just added the demo, so you didn't miss it earlier)
Just a small addition
It should be "overrideDateFormat":"%d/%m/%Y" in the HTML inline options.
In http://dev.jtsage.com/jQM-DateBox2/demos/script/split.html it states "dateFormatOverride":"%d/%m/%Y"} however this is incorrect and doesn't work. Just a heads up for anyone else with this issue.
Yes you need to use this method.
<!-- fix american date formatting -->
<script type="text/javascript">
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'overrideDateFormat': '%d/%m/%Y',
'overrideHeaderFormat': '%d/%m/%Y'
});
</script>
So I can set the date format on the Calendar Extender to it displays just the month, but you would still have to select the Year, then the Month, then the Day.
I would like to just select the Year, then the Month.
<cc2:CalendarExtender ID="DateOfReleaseCalendarExtender" runat="server"
TargetControlID="DateOfReleaseTextBox"
Format="MMMM yyyy" />
That is not a built-in feature, no. You'll have to extend it yourself. I would probably hook into the Javascript events--whichever one you think makes sense in your situation.
This requires patching the CalendarExtender part of the AjaxControlToolkit assembly.
I found a blog post that explains how to do something very similar to what you are trying to do: Patching the CalendarExtender Control