I have got below code, where I am sending the formatted date and time to my XSLT and which is giving a XML as output.
#importXSLT "tcm:228-190529-2048" As expandXSLT
#importXSLT "tcm:228-642694-2048" As renderXSLT
Dim xml, currentDateTime, datLong , datLongTime , fullDate
Set xml = getNewDomDocument()
xml.loadXML TDSE.GetListPublications(3)
expandXSLT.input = xml
Call expandXSLT.addParameter("publication", Component.Publication.Id)
expandXSLT.transform
xml.loadXML(expandXSLT.output)
'WriteOut xml.xml
currentDateTime = now()
datLong = FormatDateTime(currentDateTime, 1)
datLongTime = FormatDateTime(currentDateTime, 3)
fullDate = datLong &" "& datLongTime
renderXSLT.input = xml
Call renderXSLT.addParameter("currentPublishedDate", CStr(fullDate))
renderXSLT.transform
WriteOut renderXSLT.output
Set xml = Nothing
Now above logic for doing date formatting is same for two outputted XML, but suprising I am getting different output for both the files.
First File gives - Sunday, October 23, 2011 8:52:36 AM as output
Second File gives - 23 October 2011 09:14:45 as output.
Please suggest what can be reason as well as solution also, and one more thing if I want output as below for both the file as 23 October 2011 09:14:45 AM
Thanks!!
Before you do the date formatting, try to explicitly set the locale using something like SetLocale(2057).
2057 is UK format which seems to be what you want, otherwise look at this Locale ID Chart to find the correct value.
Related
I have a LaTeX document that I convert to HTML using Pandoc. My template references the $date$ variable like so:
$if(date)$
<p>$date$</p>
$endif$
As usual, the value of $date$ is the ISO formatted date (e.g., 2022-06-17 for today). I want to format it so that it has a human-readable format, so that I can get this output:
<p>17 Jun 2022</p>
Usually, one can achieve this using format strings (for the above example: %d %b %Y). Is there a way to do that for the Pandoc's output?
A simple Lua filter can achieve this.
The following filter code is adapted from Setting the date in the metadata from the Pandoc documentation.
-- filters/date-format.lua
function Meta(meta)
if meta.date then
local format = "(%d+)-(%d+)-(%d+)"
local y, m, d = pandoc.utils.stringify(meta.date):match(format)
local date = os.time({
year = y,
month = m,
day = d,
})
local date_string = os.date("%d %b %Y", date)
meta.date = pandoc.Str(date_string)
return meta
end
end
---
# test.md
title: My Title
date: 2022-06-18
---
<!-- templates/date.html -->
$if(date)$
<p>$date$</p>
$endif$
Compile with the command pandoc --data-dir=. --template=date --lua-filter=date-format.lua test.md -o test.html.
The output should be <p>18 Jun 2022</p>.
I am trying to create a simple script that prompts the user for their birthday, formatted as 10.02.20, then takes that string and turns it into text, such as October 2nd 2020. I have the following code:
Dim bd, message, title ' define variables
title = "What is your birthday?" ' set variable
message = "Format like so: 12.15.07; 3.03.05" ' set variable
bd = InputBox(message, title) ' prompt user
Dim year
year = bd.Substring(6, 2)
Dim month
month = bd.Substring(0, 2)
Dim day
day = bd.Substring(3, 2)
msgbox bd ' for testing
call msgbox(year + month + day) 'also testing
And I am getting an error after the prompt, ...\Desktop\test.vbs(8, 1) Microsoft VBScript runtime error: Object required: '12.23.03' and I am not sure what it means, Object Required.
Any fixes or suggestions would be very much appreciated.
You cannot use Substring in VBScript. You can use Mid instead:
Dim year
year = Mid(bd, 7, 2)
The first character in a string is at position 1, not 0, so I adjusted your parameter from 6 to 7.
Also, to concatenate strings, although + works, you can also use &:
call msgbox(year & month & day)
You can use this function in vbscript : FormatDateTime(date,format)
Parameter Description
date Required.
Any valid date expression (like Date() or Now())
format Optional.
A value that specifies the date/time format to use can take the following values:
0 = vbGeneralDate - Default. Returns date: mm/dd/yyyy and time if specified: hh:mm:ss PM/AM.
1 = vbLongDate - Returns date: weekday, monthname, year
2 = vbShortDate - Returns date: mm/dd/yyyy
3 = vbLongTime - Returns time: hh:mm:ss PM/AM
4 = vbShortTime - Return time: hh:mm
Dim Title,Input
Title = "format date"
Input = InputBox("Enter your date of Birthday !",Title,"10.02.20")
Input = FormatDateTime(Replace(Input,".","/"),1)
MsgBox Input
The innerText looks like this:
9999
NA 1299
1/1/2015
7:01:35 EST
Cleanup Time
12/31/2015
12/31/2015
I'm trying to work with an object's innerText by doing the following:
Set arr_data = Sys.Browser.("iexplore").Page("...")...
For i = 0 To array_data.length-1
Set element = array_data(i)
Set text = element.innerText //error happens on this line
If InStr(text, "Cleanup Time")<> 0 Then
Log.Message("Found")
Else
Log.Message("Not Found")
End If
Next
The error I am getting is:
Microsoft VBSCript runtime error
Object required:'[string: "9999 IMP 9999"]'
I've also tried indexing by using
Set text = element.innerText(i)
But get a
Unknown runtime error
I've checked the objects in the debugger up to the point of Set text, and everything looks good.
The problem is we are trying to Set text, when we should just be using
text = element.outerText
I am using the codeigniter time helper to echo the TIMESTAMP (CURRENT_TIMESTAMP) row of my mysql database.
The timestamp in my database in raw format is: 2011-11-15 14:40:45
When I echo the time in my view using the helper i get the following: 15/11/2011 02:40
My time now appears to be in AM. Why???
This is the code I use to echo the time:
$the_date = mdate('%d/%m/%Y %h:%i', strtotime($row->date))
echo $the_date
You need to change the format of your data when returning it from the database. Chage the lowercase h (%h) to a capital H (%H) to return 24-hour format rather than the 12 hour you're currently getting.
You're code should look like the below:
$the_date = mdate('%d/%m/%Y %H:%i', strtotime($row->date))
I am working on an application in which I need to get the current year, month, and day. Is there a way to get this information in the pre block of a rule?
Can I get this data as a string or a number or both?
There are currently time functions documented on http://docs.kynetx.com/docs/Time but none of them seem to work for what I am trying to do.
Is there a way to set the timezone when getting this data?
I was able to do it using strftime which appears to be an undocumented feature so use with caution.
ruleset a60x518 {
meta {
name "date-test"
description <<
date-test
>>
author "Mike Grace"
logging on
}
rule testing {
select when pageview ".*"
pre {
retTime = time:strftime(time:now({"tz":"America/Denver"}), "%c");
month = time:strftime(time:now({"tz":"America/Denver"}), "%B");
year = time:strftime(time:now({"tz":"America/Denver"}), "%Y");
day = time:strftime(time:now({"tz":"America/Denver"}), "%d");
}
{
notify("time",retTime) with sticky = true;
notify("month",month) with sticky = true;
notify("year",year) with sticky = true;
notify("day",day) with sticky = true;
}
}
}
App run on example.com twice. Once with the timezone set to New York and onother time set to Denver
I used this site http://www.statoids.com/tus.html to get the correct strings to use for the timezone. I have no idea if they all work. I just found this site and tried a few and they worked so use with caution.
Perhaps the docs got reverted. For convenience, here is the documentation for strftime:
time:strftime()
Convert a datetime string to a different format
Usage
time:strftime(`<string>`,`<format>`)
Valid format arguments to strftime follow the POSIX strftime conventions.
Samples
time:strftime(xTime,”%F %T”) # 2010-10-06 18:15:24
time:strftime(xTime,”%F”) # 2010-10-06
time:strftime(xTime,”%T”) # 18:19:29
time:strftime(xTime,”%A %d %b %Y”) # Wednesday 06 Oct 2010
time:strftime(xTime,”%c”) # Oct 6, 2010 6:25:55 PM
The other time functions:
time:now()
Current datetime based upon user’s location data
Usage
time:now()
time:now({“tz” : <timezone>)
time:new()
Create a new RFC 3339 datetime string from a string (allows some flexibility in how the source string is formatted)
Usage
time:new() # Equivalent to time:now()
time:new(<string>)
Valid formats for the datetime source string can be found in ISO8601 (v2000).
time:add()
Add (or subtract) a specific number of time units to a source string
Usage
time:add(<string>,{<unit> : n})