Getting Data In

In a CSV file, how do you sort date and time separately?

mdmaala
Communicator

hi!

I have a CSV file that indicates Date and Time in one column and is displayed like this 2019/03/05 17:05:04 I want to sort the date and time separately.

is there any way I can do this? thanks!

Tags (2)
0 Karma
1 Solution

vnravikumar
Champion

Hi @mdmaala

You can try this rex also, it will result in two new columns Date and Time

| makeresults 
| eval date_time="2019/03/05 17:05:04" 
| rex field=date_time "(?P<Date>\d{4}\/\d{2}\/\d{2})\s(?P<Time>\d{2}\:\d{2}\:\d{2})"

View solution in original post

0 Karma

vnravikumar
Champion

Hi @mdmaala

You can try this rex also, it will result in two new columns Date and Time

| makeresults 
| eval date_time="2019/03/05 17:05:04" 
| rex field=date_time "(?P<Date>\d{4}\/\d{2}\/\d{2})\s(?P<Time>\d{2}\:\d{2}\:\d{2})"
0 Karma

mdmaala
Communicator

Thank you so much! it works perfectly. but how about if I want to separate the date and time for all the date and time included in the table? is that possible?

0 Karma

mdmaala
Communicator

I see now I understand. In my table the field name is Date_Time so what I did was this:

source="C:\Users\NPIE-MDMAALA\Documents\PATLITE\*" host="DESKTOP-G546H69" sourcetype="csv" | rename "Green information" AS "Green" | rename "Amber information" AS "Amber" | rename "Red information" AS "Red" | rename "User name" AS Username | rename "MAC Address" AS "MAC_add" | rex field=Date_Time "(?P\d{4}\/\d{2}\/\d{2})\s(?P\d{2}:\d{2}:\d{2})" |

is this correct?

0 Karma

vnravikumar
Champion

Hi @mdmaala, specify your datetime field in the rex statement

your query...| rex field=date_time "(?P<Date>\d{4}\/\d{2}\/\d{2})\s(?P<Time>\d{2}\:\d{2}\:\d{2})"

here date_time is the field name that you want to split, It will give two fields Date and Time.
Please let me know if you need more info.

0 Karma

mdmaala
Communicator

Oh! Never mind! I already figured out what to do based on your last comment. and It really worked well! thank you so much @vnravikumar !!

0 Karma

niketn
Legend

@mdmaala, try the following regular expression based extraction (with run anywhere example based on your data). If the field name is DateTime the regex extract two fields Date and Time separately.

| makeresults
| eval DateTime="2019/03/05 17:05:04"
| rex field=DateTime "^(?<Date>[^\s]+)\s(?<Time>.*)$"
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...