I have this code to take date from database and to fill with it an input field in powermail:
termin = TEXT
termin.stdWrap.dataWrap = DB:tx_seminars_seminars:{GP:tx_seminars_pi1|uid}:begin_date
termin.stdWrap.outerWrap = {|}
termin.insertData = 1
termin.htmlSpecialChars = 1
Value from field begin_date is displayed in powermail form, but i need to dispay it in human readable format (in DB it`s unix time)
My problem is to fromat tstamp to %d %m %y
How to format it?
stdWrap has a date attribute.
#Example where a timestamp is imported:
test.value.field = tstamp
test.value.date = d.m.Y H:i:s
http://wiki.typo3.org/TSref/stdWrap#date
EDIT:
Please note, that TEXT is an instance of stdWrap. You don't need to modify stdWrap for that simple wrapping. Adding {} there will modify the timstamp so that date is unable to get the right value.
Here is the best solution to add the date as like times ago format:
Render the fluid section as below:
<f:render section="timeAgo" arguments="{posted:'{posting.datePosted}'}" />
Fluid section:
<f:section name="timeAgo">
<f:variable name="now" value="{f:format.date(date: 'now',format:'%s')}" />
<f:variable name="posted" value="{f:format.date(date:'{posted}',format:'%s')}" />
<f:variable name="diff" value="{now - posted}" />
<f:if condition="{diff} < 60">
<f:then>Now</f:then>
<f:else if="{diff} < 3600">
<f:format.number decimals="0">{diff / 60}</f:format.number> minute ago
</f:else>
<f:else if="{diff} < 86400">
<f:format.number decimals="0">{diff / 3600}</f:format.number> hours ago
</f:else>
<f:else if="{diff} < 604800">
<f:format.number decimals="0">{diff / 86400}</f:format.number> days ago
</f:else>
<f:else if="{diff} < 2419200">
<f:format.number decimals="0">{diff / 604800}</f:format.number> weeks ago
</f:else>
<f:else if="{diff} < 29030400">
<f:format.number decimals="0">{diff / 2419200}</f:format.number> months ago
</f:else>
<f:else>{f:format.date(date: '{posted}',format:'%d %B, %Y')}</f:else>
</f:if>
</f:section>
And it's done just pass your correct variable object at arguments="{posted:'{posting.datePosted}'}".
Thank you!
Related
I'm having a problem with Coldfusion's DateDiff(). I'm trying to get the difference between two dates with times, like the following examples:
fromdate=06/11/2017 22:10
todate =16/11/2017 23:20
should return:
10 days, 1 hour and 10 minutes
fromdate=06/11/2017 22:10
todate =16/11/2017 20:20
should return:
9 days, 22 hours, 10 minutes
Any help?
Code:
<cfset dtFrom = "11/06/2017 22:10" />
<cfset dtTo = "11/16/2017 23:20" />
<cfoutput>
#DateDiff( "d", dtFrom, dtTo)# Days,
#DateDiff( "h", dtFrom, dtTo) % 24# Hours
#DateDiff( "n", dtFrom, dtTo) % 24 % 60# Minutes
</cfoutput>
In addition to the previous suggestion, DateDiff() isn't going to understand those specific strings or that "06/11/2017" should mean November 6. The result will be:
158 days 1 hours 10 minutes
For it to work as expected, you must convert the strings into date objects first. For example use LSParseDateTime with the right Locale.
fromDate = lsParseDateTime("06/11/2017 22:10", "English (UK)", "dd/MM/yyyy hh:mm");
toDate = lsParseDateTime("16/11/2017 23:20", "English (UK)", "dd/MM/yyyy hh:mm");
or possibly:
fromDate = lsParseDateTime("06/11/2017 22:10", "English (UK)");
toDate = lsParseDateTime("16/11/2017 23:20", "English (UK)");
Here is one way.
totalMinutes = datediff("n", fromDate, toDate);
days = int(totalMinutes /(24 * 60)) ;
minutesRemaining = totalMinutes - (days * 24 * 60);
hours = int(minutesRemaining / 60);
minutes = minutesRemaining mod 60;
writeoutput(days & ' days ' & hours & ' hours ' & minutes & ' minutes');
Hi I am looking for a way to add 2 hidden fields in my form that hold the current date and current time.
<input type="hidden" name="date" value="CurrentTime">
<input type="hidden" name="time" value="CurrentDate">
Thank you.
You can do this using JavaScript.
Include some ids in your input elements, so you can identify them in JS:
<input type="hidden" id="date" name="date" value="CurrentTime">
<input type="hidden" id="time" name="time" value="CurrentDate">
You can then use JS's Date() function to get the current Date. Create a variable as a new Date(), then use the methods on that variable to get the parts of the date and time you're after!
Here's the script you'll need:
<script type="text/javascript">
var d = new Date();
// Set the value of the "date" field
document.getElementById("date").value = d.toDateString();
// Set the value of the "time" field
var hours = d.getHours();
var mins = d.getMinutes();
var seconds = d.getSeconds();
document.getElementById("time").value = hours + ":" + mins + ":" + seconds;
</script>
Here's a JSFiddle to see it in action: https://jsfiddle.net/y3go8hm8/ -
note, I've changed the type to text, rather than hidden - or you wouldn't be able to see it working!)
Formatting
You can format the date however you like, so my example above gives you the date as "Mon 12 Jun 2010" format.
Let's say you want dd/MM/yyyy format:
// Get today's date
var day = d.getDate();
var month = d.getMonth() + 1; // The months are 0-based
var year = d.getFullYear();
// Set the date field to the current date
document.getElementById("date").value = day + "/" + month + "/" + year;
Caveat of this is, that months or days less than 10 will only display to 1 digit (e.g. 12/3/2014). Likewise, this applies for the time, too.
You can loop through the day and month and prepend 0, if you wish;
if (day < 10) {
day = "0" + day;
}
if (month < 10) {
month = "0" + month;
}
and do the same for the hours and mins of the time:
if (hours < 10) {
hours = "0" + hours;
}
if (mins < 10) {
mins = "0" + mins;
}
And then assign the values to the fields, as above.
Here's a JSFiddle of this in action, too: https://jsfiddle.net/y3go8hm8/1/
Hope this helps! :)
The below mentioned is the calculation field to fetch the prior months.
CASE [TimeFrame]
when 'DateMonth' then if [Months between today and Date]=0 then 'show' end
when 'Last2Months' then if [Months between today and Date]>=0 and [Months between today and Date]<=1 then 'show' end
when 'Last3Months' then if [Months between today and Date]>=0 and [Months between today and Date]<=2 then 'show' end
else 'hide'
end
The above mentioned Calculation is working as expected for Last2Months and Last3Months but its not showing any result for the current month.
Example if the user selects 11/1/2015 then,
DateMonth should be November--currently no data is shown...
Last2Months should be November and October--working as expected
Last3Months should be November,October and September --working as expected.
Also i need to add up the months as rolling sum and display automatically instead of the drop down selected.
Please find the twbx attached.
Any inputs would greatly be appreciated.
You have IF statements within your CASE statement that do not have an ELSE which means you will get some NULLs in certain cases (they will not be caught by the ELSE in your CASE).
I would rewrite like this. See if this gets you your results:
IF [TimeFrame] = 'DateMonth' AND [Months between today and Date] = 0 THEN 'show'
ELSEIF [TimeFrame] = 'Last2Months' AND [Months between today and Date] >= 0 AND [Months between today and Date] <= 1 THEN 'show'
ELSEIF [TimeFrame] = 'Last3Months' AND [Months between today and Date] >= 0 AND [Months between today and Date] <= 2 THEN 'show'
ELSE 'Hide'
END
I am trying to wrap every 3rd item in a menu generated with TypoScript.
This is my menu:
tt_content.menu.20.4 >
tt_content.menu.20.4 < tt_content.menu.20.1
tt_content.menu.20.4.stdWrap.outerWrap = <div class="my-menu">|</div>
tt_content.menu.20.4.1.wrap = <ul>|</ul>
tt_content.menu.20.4.1.NO {
doNotLinkIt = 1
stdWrap.htmlSpecialChars = 0
stdWrap.cObject = COA
stdWrap.cObject {
# title
10 = TEXT
10 {
field = title
typolink.parameter.field = uid
typolink.ATagParams = class="more"
}
# abstract
20 = TEXT
20 {
field = abstract
htmlSpecialChars = 1
wrap = <span>|</span>
}
}
}
Via How can I apply a different wrap to every menu item? I know how to wrap every item different, is there a way to wrap three items together?
And when there are more than 3 % x = 0 items, e.g. 14, the last opening tag has to be closed with the last item.
Current output:
<ul class="csc-menu csc-menu-1">
<li>
Page 1
</li>
<li>
Page 2
</li>
<li>
Page 3
</li>
<li>
Page 4
</li>
<li>
Page 5
</li>
<li>
Page 6
</li>
<li>
Page 7
</li>
<li>
Page 8
</li>
<li>
Page 9
</li>
</ul>
Wanted output, something like this:
<div class="pack">
Page 1
Page 2
Page 3
</div>
<div class="pack">
Page 4
Page 5
Page 6
</div>
<div class="pack">
Page 7
Page 8
Page 9
</div>
<div class="pack">
Page 10
Page 11
</div>
Basically you are asking 2 questions.
But for both you might use optionSplit. [1.]
First: "wrap every 3rd item"
Your code would look like that:
tt_content.menu.20.4.1.NO.allWrap = |*| <ul>|</ul> || <ul>|</ul> || <ul class="third">|</ul> |*|
Second: "is there a way to wrap three items together"
Your code would look like that:
tt_content.menu.20.4.1.NO.allWrap = |*| <div class="threepack"> <ul>|</ul> || <ul>|</ul> || <ul>|</ul> </div> |*|
How optionSplit ist working in these cases:
You have no first and last part, so the middle part is cycled over all items.
The middle part consists of 3 subparts which are cycled too.
Hope that helped.
PS: Don't forget to accept an answer ;-)
Links:
http://wiki.typo3.org/TSref/optionSplit
The below typoscript may help you (It's for page menu to group 3 page links together and you need to modify it according to your requirements.):
page.234 = COA
page.234{
wrap = <ul> |</ul>
10 = HMENU
10.1 = TMENU
10.special = directory
10.special.value = 1
10.1 {
wrap = <li><ul>|</ul></li>
begin = 1
maxItems = 3
NO {
allWrap = <li> |</li>
}
}
20 < .10
20.1.begin = 6
30 < .10
30.1.begin = 9
# etc. etc.
}
I'm trying to set up a multilanguage site with typo3, but Im having some trouble. The default language of the site is German, but I also want to have it in English and French. So I went to define 2 more languages: English with ID=2 and French with ID=3
Next I added this typoscript to my template:
config.linkVars = L
config.uniqueLinkVars = 2
config.sys_language_overlay = content_fallback
config.language = de
config.locale_all = de_DE
config.htmlTag_langKey = de-DE
config.sys_language_uid = 0
[globalVar = GP:L = 2]
config.language = en
config.locale_all = en_EN
config.htmlTag_langKey = en-EN
config.sys_language_uid = 2
[globalVar = GP:L = 3]
config.language = fr
config.sys_language_uid = 3
config.locale_all = fr_FR
config.htmlTag_langKey = fr-FR
[end]
And then I added this language menu, from the extension srlanguagemenu:
10 < plugin.tx_srlanguagemenu_pi1
10{
languagesUidsList = 0,2,3
defaultLayout = 2
showLinkWithFlag = 0
showCurrent = 1
}
But the menu only shows "English". This is the exact markup:
<div class="tx-srlanguagemenu-pi1">
<div class="CUR"><img src="typo3/gfx/content_client.gif" alt="" style="width:7px; height:10px;">English</div>
<div class="SPC"> </div> <div class="INACT"></div>
<div class="SPC"> </div> <div class="INACT"></div>
</div>
Also. In the menu, the name of the pages doesn't show the translated version.
What am I doing wrong?
You need to translate not only the content of your page, but also the page. This is done via creating an "alternative_page_language" ("alternative Seitensprache" in german).
You can create an multilanguage TS menu via HMENU.special = language.
For working with translations, have a look at the INFO-Modul. There is a "Localization Overview", don't miss it:) I guess you already found the language View in the Page Modul.