can anyone provide me with a way to have Splunk convert an extracted field which is currently in milliseconds to HH:MM:SS?
...| fieldFormat inSeconds = tostring(inMS/1000,"duration)
where inMS is the name of the extracted field
and inSeconds is the result you want
add | fields - inMS to remove the original field
Related
I have a spark data frame having two columns (SEQ - Integer, MAIN_DATE - Date) as:
Now I want to add a column based on the condition that if the format of MAIN_DATE is "MMM-YYYY" then it should be converted to Last day of the month and new data frame should look like this:
Any suggestion will be much appreciated.
You can use Spark's when/otherwise methods in order to operate differently for each different date format of the MAIN_DATE column.
More specifically, you can simply match the MMM-yyyy date format values of the column based on the field's String length (since we know that those values we always have 8 characters) as a condition in when and then:
use to_date to convert the String value to a valid date based on a format we give as an argument, and
use last_date to get the last day of the month each curry date in MAIN_DATE is referring to.
As for the "regular" rows with the dd-MMM-yyyy date format, just a to_date conversion would be sufficient within the otherwise method.
After that, all there's left to do is to convert the dates back to the desired dd-MMM-yyyy format (because to_date converts a given date to the yyyy-MM-dd format).
This is the solution in Scala (split in into two withColumns to make it more readable, instead of an one-liner):
df.withColumn("END_DATE",
when(length(col("MAIN_DATE")).equalTo(8), last_day(to_date(col("MAIN_DATE"), "MMM-yyyy")))
.otherwise(to_date(col("MAIN_DATE"), "dd-MMM-yyyy")))
.withColumn("END_DATE", date_format(col("END_DATE"), "dd-MMM-yyyy"))
This is what the resulting df DataFrame will look like:
+---+-----------+-----------+
|SEQ| MAIN_DATE| END_DATE|
+---+-----------+-----------+
| 1|16-JAN-2020|16-Jan-2020|
| 2| FEB-2017|28-Feb-2017|
+---+-----------+-----------+
I need help to convert Numbers into date format using Power Query Editor in either Excel or PowerBI
The date appears in number form like this 930101 and I want to convert it to normal Uk date format
Not sure which one is month and which one is date among "0101" in your string. But you can handle this your self and follow this below steps for get your required output in Power Query Editor-
First, split your string value using fixed 2 character and your data will be divide into 3 column now. define which one is Year, Month and Day.
Now, merge those 3 column maintain the UK pattern DD/MM/YY using a separator "/" and you will get a string like "01/01/93".
Finally, create a custom column using the below code-
Date.From([Merged],"en-GB")
Here is the final output-
In the above image, you can see the date in still US format just because of my Laptop's locally setup.
I'm trying to convert a epoch timecode to a date in Pentaho Spoon. I use an input text file to extract fields from. I want to export the fields in a database but there is this timestamp field that contains epoch timestamps like this "1480017396", the datatype is set as an integer and the field is named timestamp. I want to convert with it with Select value.
So I go to the next step and use the select value option to select the field and change the datatype to Date with a format of dd/MM/yyyy the result gives me all kinds of dates in 18-01-1970 range. I tried everything (Different formats etc.) but I just can't seem to solve it.
Any guesses? Image of output
The time in epoch is in miliseconds, not seconds, so, take your number, multiply by 1000, and turn to date.
See that if you divide, the date goes back a few ... and multiply it you get the correct date because of the timestamp.
Feels like an obvious question, but Stata help hasn't yielded answers. Most Stata users are interested in converting a non-date variable into a date variable, but I want the opposite.
I have a date variable date, type long, format %tdCCYYNN. I'm trying to append it to a dataset in which the same variable date is type long and format %12.0g. To accurately do this, I need to convert date in the first dataset from %tdCCYYNN to %12.0g. When I do format %12.0g date, date values change to incorrect ones.
Let's say, in the first dataset, I have date=201204. I still want it to read 201204, just as a %12.0g variable. Is there a way to do this?
I +1 all the comments above by Nick and William and suggest you read help datetime. I have been using Stata for a few years and still frequently visit this help file. Stata's date/time functionality is fantastic and you will benefit from learning it earlier rather than later.
I would convert the other data to Stata date format. Really. But if you need to convert your %td date to an "integer YYYYNN" date, then pass through a temporary file. If you write your %td date to plain text, then it will keep the displayed format and you can read it back as an integer YYYYNN date.
// data that matches your decsription
clear
set obs 1
generate date = date("20120401", "YMD")
format date %tdCCYYNN
list
// write to tempfile as plain text
tempfile plainText
outsheet using "`plainText'"
// read back with dates as integers
preserve
tempfile StataData
insheet using "`plainText'", clear
rename date dateInteger
save "`StataData'"
restore
// merge to original data
merge 1:1 _n using "`StataData'"
list
describe
This yields the following.
. list
+---------------------------------+
| date dateIn~r _merge |
|---------------------------------|
1. | 201204 201204 matched (3) |
+---------------------------------+
. describe
Contains data
obs: 1
vars: 3
size: 7
-----------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-----------------------------------------------------------------------------------------------------
date int %tdCCYYNN
dateInteger long %12.0g
_merge byte %23.0g _merge
-----------------------------------------------------------------------------------------------------
Sorted by:
Note: Dataset has changed since last saved.
But I suggest you take advantage of Stata's date/time functionality.
I export data in csv format from sql server database. It contain 5 column. one column have date and time value. When i checked the date -time value i found date time value is in wrong format. I add the filter but filter not applied on some data. I try to format the data in same format but formatting did not applied on the data. I tried everything to fix the issue but it is not getting fix.
I have attached the sample data please check it from your end.
7/12/2013 14:50
8/12/2013 20:14
9/12/2013 11:38
10/12/2013 15:31
13/12/2013 12:45:50
13/12/2013 14:35:42
13/12/2013 14:37:40
14/12/2013 17:00:10
18/12/2013 14:57:35
Data started from 13/12/2013 12:45:50 are not getting change in date time format.
The trouble is that your dates are in french format dd/mm/yyyy you can force them to datetime with the following line :
[datetime]::ParseExact("7/12/2013 14:50", "d/MM/yyyy HH:mm", $null)
[datetime]::ParseExact("13/12/2013 12:45:50", "d/MM/yyyy HH:mm:ss", $null)
Be carefull in you case sometime you've got seconds and a double space between day and time.