Unable to send Date in dd MMM yyyy format as a field from telegraf to Influx

Hello Everyone, I want to send a date with the format e.g. 30 May 2021 as a field from telegraf to Influxdb. I am using Powershell script to create this date value and send the same to Influxdb. My commands looks as below
$ sysLastBootTime = $userSystem.ConvertToDateTime($userSystem.LastBootUpTime).tostring("dd/MM/yyyy") write-host "Windows_rebootpending,host=$($ComputerName.ToString()) Days=$($sysuptime.Days.ToString()),LastBootTime=$($ sysLastBootTime ) $($date)" If I format the date to ddMMyyyy its being sent else dd MM yyyy or dd MMM yyyy or dd/MM/yyyy results in no metrics sent. Could someone suggest or help on this to make work.

If you are creating this date in a Powershell script, in order to send it to
InfluxDB, and you find that the format ddMMyyyy works, why not just use that?

What is so special to you about creating a date in a format that InfluxDB
doesn’t like, that you want to spend time trying to get it to accept it? Why
not just go with the format InfluxDB is happy with?


Thanks for having a look. I need to show up the date in a single column in DD.MM.YYYY or ddMMMyyyy format in grafana dashboard.

In that case I suggest sending it to telegraf / InfluxDB as an Epoch timestamp
and let Grafana do the formatting.

I assume Windows Powershell knows how to do Epoch timestamps?


I tried it but could see no valid unit for formatting epoch values in field formatting options. I am not sure if field can format epoch valuee

I’ve been racking my brains trying to figure this out and unhelpful/sarcastic comments (@Pooh) really don’t help anyone.

I was using the Influx CLI to pass information to the DB and it was working fine until i tried to provide a timestamp for the data. (we collect stats in batches which are grouped by hour so we can’t let Influx assign the time)
For example:
$PushToInflux = & “C:\Program Files\InfluxData\influx.exe” write -b $Bucket -p s $DataValues

This worked for me: (ref: 01 - InfluxDB: First Steps and Guide-Lines – Wiki-WebPerfect)

$Header = @{Authorization = “Token <YOUR_AUTH_TOKEN>”}
Invoke-WebRequest -Uri ‘http://<your_InfluxDB_server>:8086/api/v2/write?org=<INFLUX_YOUR_ORG>&bucket=<YOUR_BUCKET>’ -Header $Header -Method POST -Body ‘test_measurement_cpu,host=server01,os=windows cpuload=33 1587646932000000000’

To get the timestamp in the correct format i used:
[Datetime]$logHour = $myTimeValue #The original datetime of: 2022-08-18T07:00:00Z
[int64]$ETime = “$((DateTimeOffset).ToUnixTimeMilliseconds())” #Gives you: 1660809600000000000

In the example above replace the timestamp 1587646932000000000 with the variable $ETime
So the -Body variable contains:
$Body = ‘MyMeasurement,TagName=’+$someVariable+’ Field1=‘+$Var1+’ ‘+$ETime+’’
(remember to double the single quotes in Powershell)
The Body output should read:
'MyMeasurement,TagName=MyVariable Field1=TextVar1 1660809600000000000

Then pass the whole thing to Invoke-WebRequest and it should give you the 204 response:
Invoke-WebRequest -Uri $InfluxConnect -Header $Header -Method POST -Body $Body

Hope this helps :slight_smile: