date,time format

Hello to all
for project I need special sintax in http get request to server. I use fetch tool on MT but I need time and date from MT in special format understandable for server like this:
date,time example 300918,202130 (this is how remote server understand)
Where:
300918 = 30.sep.2018.
202130 = 20h 21min 30sec

How to achave this ? MT use NTP for clock

[admin@xxxxxxxx] > system clock print
time: 21:10:31
date: sep/30/2018
time-zone-autodetect: yes
time-zone-name: Europe/Belgrade
gmt-offset: +02:00
dst-active: yes

[admin@xxxxxxxxxx] /system ntp client> print
enabled: yes
primary-ntp: 10.20.20.254
secondary-ntp: 0.0.0.0
server-dns-names:
mode: unicast
poll-interval: 15m
active-server: 10.20.20.254
last-update-from: 10.20.20.254
last-update-before: 55s310ms
last-adjustment: 13ms692us

You mean like this?

{
  :local mydatetime
  :local time [/system clock get time]
  :local date [/system clock get date]
  :local month [:tostr ([:find \
    "janfebmaraprmayjunjulaugsepoctnovdec" [:pick $date 0 3] \
  ]/3+1)]
  :if ([:tonum $month]<10) do={
    :set month "0$month"
  }
  :set mydatetime ( \
    $month.[:pick $date 4 6].[:pick $date 9 11].",". \
    [:pick $time 0 2].[:pick $time 3 5].[:pick $time 6 8] \
  )
  :put "Current date/time in DDMMYY,HHMMSS format is: $mydatetime"
}

-Astounding

great code, thank you!!

@Astounding

With DDMMYY,HHMMSS format the code may be:

 :set mydatetime ( [:pick $date 4 6].$month.[:pick $date 9 11].",".[:pick $time 0 2].[:pick $time 3 5].[:pick $time 6 8] )

I suggest a more light code, without division.

# BEGIN Script v2

# BEGIN Config
# END Config

:local Date [/system clock get date]
:local Time [/system clock get time]
:local Month [:tostr ([:find [:toarray "jan,feb,mar,apr,may,jun,jul,ago,sep,oct,nov,dec"] [:pick $Date 0 3]]+1)]
:put ("Month=".$Month)
:if (:len $Month<2) do={
  :set Month "0$Month"
 }
#To be sure
:set Month [:pick [$Month] 0 2]
:put ("Month=".$Month)

# Format YYYYMMDD-HHMMSS
:global DateTimeCode ([:pick $Date 7 11].$Month.[:pick $Date 4 6]."-".[:pick $Time 0 2].[:pick $Time 3 5].[:pick $Time 6 8])
# Format DDMMYY-HHMMSS
#:global DateTimeCode ([:pick $Date 4 6].$Month.[:pick $Date 9 11]."-".[:pick $Time 0 2].[:pick $Time 3 5].[:pick $Time 6 8])

:put ("DateTimeCode=" . $DateTimeCode)

# END Script

The :put, only for testing, may be removed when copy in Mikrotik script.

I modify for better use (adding “-”) but… how i can replace on 1-9 months before month number zero?
Example:
Now: 2022-2-15_-10-32-16
I want: 2022-02-15
-_10-32-16

# BEGIN Script v2

# BEGIN Config
# END Config

:local Date [/system clock get date]
:local Time [/system clock get time]
:local Month [:tostr ([:find [:toarray "jan,feb,mar,apr,may,jun,jul,ago,sep,oct,nov,dec"] [:pick $Date 0 3]]+1)]
:put ("Month=".$Month)
:if (:len $Month<2) do={
  :set Month "0$Month"
 }
#To be sure
:set Month [:pick [$Month] 0 2]
:put ("Month=".$Month)

# Format YYYYMMDD-HHMMSS
:global DateTimeCode ([:pick $Date 7 11]."-".$Month."-".[:pick $Date 4 6]."_-_".[:pick $Time 0 2]."-".[:pick $Time 3 5]."-".[:pick $Time 6 8])
# Format DDMMYY-HHMMSS
#:global DateTimeCode ([:pick $Date 4 6].$Month.[:pick $Date 9 11]."-".[:pick $Time 0 2].[:pick $Time 3 5].[:pick $Time 6 8])

:put ("DateTimeCode=" . $DateTimeCode)

:log info message=[:put ($DateTimeCode)]

# END Script