I'm outputting to CSV and I'd like my dates in ISO8601 format, such as 2014-04-02T19:21:36.292Z, but I keep getting dates like Mar 27 2014 17:56:33 in my csv.
I'm fine to create a second intermediate string variable to do the formatting, but it yields the same result.
I see that there's a "sprintf" function in Logstash, but it seems you can do EITHER variable references OR date formats (which I assume will get the current system date time), but I don't think you can do both. I other words, I don't think it lets you apply a date format to an existing date variable, or if it does I'm not sure what the syntax would be.
Plenty of false hits on Google and stack, but all are about parsing.
Ironically stdout happens to output in the format I want, using stdout { debug => true codec => "rubydebug"}. Maybe that could somehow help in my case, not sure? Although other folks might want some other arbitrary format.
Try this one. Add a new "date" field then output to csv.
filter {
ruby {
code => '
require "time"
event["date"] = Time.parse(event["#timestamp"].to_s).iso8601;
'
}
}
Related
I'm trying to convert, in a RPG program, a date from a file (it's from the DSPJRN command, so the field si 6 numeric, in JOB format).
I want to use it as a date in my program, but I can't achieve it correctly.
I have tried to describe a field with type "D": date, keyword datfmt(*job) to convert the value from the file, but datfmt(*job) is incorrect (error RNF0612)
I have tried to retrieve the job Date format from a CLP program with RTVJOBA DATFMT(&FMT), and use the variable in RPG to convert the date like this
eval ztJODATE = %date(JODATE:FMT)
but it doesn't compile : error RNF0606 . I think that I can't use a variable for the format in the %date built-in function.
Is this a way to do what I want, or am I forced to transform the date value in SQL before using its value in RPG?
PS: I don't want to hardcode the format in my RPG program!
You can specify *JOBRUN for %DATE.
eval ztJODATE = %date(JODATE:*JOBRUN)
Note that RPG retrieves the job date format during initialization of the module, so if you change the job date format while the program is running, RPG will not understand the date.
Rather than using DSPJRN to an outfile, the recommended way to retrieve and process journal entries would be to use one of the programatic interfaces provided by IBM i.
Retrieve Journal Entries (QjoRetrieveJournalEntries) API
QSYS2.DISPLAY_JOURNAL() stored procedure
You could also use a *TYPE3 or higher format for the output file. Rather than the separate job formatted data & time fields, there's a single char(26) system timestamp field.
Having said that, there is a Convert Date and Time Format (QWCCVTDT) API that accepts '*JOB' as an input format specifier..
while reading the spreadsheet using perl, how the time format data (in a cell) in spreadsheet got read by perl ?
I tried to read text and numeric type data from a cell in worksheet, as a result, it got read as text and numeric in perl,
but while reading a time format data, it got converted to some float value(of format - HH:MM:SS/HH:MM/MM:SS), my doubt is that, how the time format ([H]:MM:SS) from a cell got read by perl ?
For example:
$cell holds the value of 13:7(is in time format [H]:MM:SS format in spreadsheet)
while reading it using perl,
$type = $cell->type() //returns the type : Numeric/Text
$format = $cell->get_format() // returns the format (i.e)if Numeric :returns time format of HH:MM:SS / HH:MM / MM:SS formats only
In such case, how data present in $cell can be read by perl? and how
other time formats such as MM:SS.0/[H]:MM:SS/YYYY-MM-DD HH:MM:SS/ [HH]:MM:SS...are identified?
In most cases (maybe all, but I've learned to be wary of statements like that), dates in Excel spreadsheets are stored as floating-point numbers where the integer part of the number is the number of days since the start of 1900 and the decimal part is how far through the day we are.
You can, of course, use that information to parse the data yourself. But there's no need to do that in a world where DateTime::Format::Excel exists.
I am trying to compare two dates.
But the temp always returns true.
Can you explain where i am going wrong
temp = (Format(CDate("27-Aug-09"), "dd-mmm-yy") > Format(CDate("07-Jul-12"), "dd-mmm-yy"))
You're formatting the values according to dd-mmm-yy - which is actually the format they're in to start with. So you're just comparing the strings "27-Aug-09" and "07-Jul-12"... at which point "2" is later than "0", so the comparison finishes really quickly.
I suspect you can just get rid of the Format calls, to compare the dates:
temp = (CDate("27-Aug-09") > CDate("07-Jul-12"))
That's assuming that CDate can handle the input, of course. (I expect that part is fine.)
If you really want to compare strings, you need to convert the dates into a naturally sortable format, e.g. yyyy-mm-dd.
I have search the internet for some time now but I can't seem to find the right answer (maybe there is but I don't understand it).
I have this code to read a file and get the date time (from Task Scheduler query).
File.txt holds the Task Scheduler query.
"TaskName","Next Run Time","Status"
"CheckFile","20:33:00, 17/1/2013",""
=======================================
Script to read a get the next run time value.
open (FILE, "<", $file) || print "WARN: Cannot open $file: $!";
#logLines = <FILE>;
if (#list = grep(/\b$keyword\b/, #logLines)) {
foreach(#list){$result = $_;}
my #sresult = split(/(?<="),(?=")/, $result);
$name = $sresult[0];
$name =~ tr/"//d;
$next_run = $sresult[1];
$next_run =~ tr/"//d;
print $next_run;
}
#list=();
#dFormat=();
#logLines=();
close FILE;
Output will be:
20:33:00, 17/1/2013
I want to modify the output into:
20:33:00, 2013-1-17 #note that I can do this just by splitting up and rearranging the numbers.
But the problem is, 17/1/2013 in Task Scheduler query is locale dependent. It could be in the following:
1/17/2013
17/1/2013
2013/1/17
1/17/13
17/1/13
13/1/17
1-17-2013
17-1-2013
2013-1-17
1-17-13
17-1-13
13-1-17
1.17.2013
17.1.2013
2013.1.17
1.17.13
17.1.13
13.1.17
Is there any cpan module that could do what I want? Could you give a script on how to achieve this?
Please no harsh comment. Thanks.
The following should get you the format:
use Win32::OLE::NLS qw( GetLocaleInfo GetSystemDefaultLCID LOCALE_SSHORTDATE );
say GetLocaleInfo(GetSystemDefaultLCID(), LOCALE_SSHORTDATE); # yyyy-MM-dd
You could try to find a date parser that understands that format, or you could use something like the following to create a format many parsers to understand.
my %subs = (
'yyyy' => '%Y',
...
);
my $pat = join '|', map quotemeta, sort { length($b) <=> length($a) } keys %subs;
$format =~ s{($pat)}{ $subs{$1} // $1 }eg;
I can tell you answer(algorithm) about your problem:
Once upon a time
Let's think about your problem:
You want to get date from every format.
But this is not possible, because it can be 12-11-10
Okay, now you must determine (somehow) which format is used.
If you can do that, you can rule the world.
Let's think about your problem more deeper:
First you must choose delimiter. (or not, if you don't want it)
it is possible to use something like this:
(\d{1,4})(\D)(\d{1,4})(\D)(\d{1,4})
After that, you have:
$1,$3,$5 # parts of data
$2,$4 # delimiters
I took 4 because i don't know where year can be placed.
After that, you must understand, which format you have:
dd-mm-yy
mm-dd-yy
yy-mm-dd
yy-dd-mm
You can add checks for that like days or months, but, as I said before:
12-11-10 = -9 <- not possible to determine, right?
So, you must have some external info about date format, for example:
which country
which branch of science
which family
etc
it belongs to.
If you can do that, you can (probably can) determine format and 12-11-10 = 12 nov 2010
The End
Update: see this discussion. It appears that the date format may be a regional setting based on the user who runs the task. If so, all you have to do is figure out how to get that regional setting...
As others have pointed out, there is no way of resolving the ambiguities in the potential date formats.
What I would explore is some way of querying the system with a known date and see what format it returns. For example, perhaps you could schedule a fake task at a (non-ambiguous) date far in the future, see what format that task is returned in, then later delete it.
That would be a bit of a messy solution, but perhaps there is a less kludgy way of doing something similar. Is task scheduler's date format the same as the system date format? If so, you could query a known date from the system.
Disclaimer: you might need to install
a font/typeface which supports
Japanese if you see messed up
characters.
I'm trying to replicate what I've been doing so far with setlocale and strftime:
setlocale(LC_ALL, 'ja_JP.utf8');
$time = mktime();
echo strftime('%x', $time), '<br>';
Output:
2010年01月06日
Using Zend_Date - but I haven't been able to reproduce the same formatting with the japanese symbols for year, month and day.
Attempt #1:
$locale = new Zend_Locale('ja_JP');
$date = new Zend_Date( strtotime('yesterday'), null, $locale);
//echo $date->toString('YYYY abcdefghijklmnopqrstuvwxy M dE');
echo $date->get('YYYY MMM DD');
Output:
2010 1月 004
Attempt #2:
echo $date->get(Zend_Date::DATE_FULL);
Output:
2010年1月5日火曜日
My first attempt I can't seem to find a working constant to produce the YEAR and day symbols. The latter uses a standardized format but I need to customize it so there's a 0 preceding the month, and I want to be more in control.
In the future I may want to make it flexible so for example, en_US dates won't have those letters coming after the year/month/day but it would only apply to languages such as Japanese and others, where it's more common, or if I misunderstood and it isn't really common then please inform me.
Thanks in advance.
Seems what I needed was the DATE_LONG constant, which internally points to 'FFFF' - I'm trying to learn the inner workings of how the Date class corresponds with the Locale class to generate the whole string including the symbols now.
Update: I kept trying to find where it actually used date units instead of date formats, found the right data I need:
<dateFormatLength type="long">
<dateFormat>
<pattern>y年M月d日</pattern>
</dateFormat>
</dateFormatLength>
So it parses this and replaces the y, M, d, returns the formatted date.