# XML dateTime format in shell script

**URL:** <https://community.unix.com/t/xml-datetime-format-in-shell-script/313256>\
**Category:** Shell Programming and Scripting\
**Created:** [July 10, 2012, 10:10am UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256 "2012-07-10T10:10:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vel4ever](https://community.unix.com/user_avatar/community.unix.com/vel4ever/32/7615_2.png) [@vel4ever](https://community.unix.com/u/vel4ever)\
**Post date:** [July 10, 2012, 10:10am UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/1 "2012-07-10T10:10:23Z")

</div>

How can i frame current date & time in the xml standard dateTime format in shell script

```nohighlight
2011-10-18T12:00:00.000000

```

I got up to the date format using the below code

```nohighlight
date '+%Y'-'%m'-'%d'T

```

---------- Post updated at 09:10 AM ---------- Previous update was at 08:53 AM ----------

I got that by using the below code

```nohighlight
date '+%Y'-'%m'-'%d'T'%T'.'%N'

```

can anyone confirm?

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_22734026db12803ebb3e059622ac3534.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [July 10, 2012, 12:05pm UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/2 "2012-07-10T12:05:58Z")

</div>

A date format string works just like the printf (either C or shell printf) format string.

```nohighlight
date '+%Y-%m-%dT%T.%N'

```

Gives you the result you want, the way you did it was correct, but confusing for other coders. %N is not part of the POSIX standard, so this will only work for GNU date (Linux, mostly).

---

<div class="post-metadata">

**Author:** ![vel4ever](https://community.unix.com/user_avatar/community.unix.com/vel4ever/32/7615_2.png) [@vel4ever](https://community.unix.com/u/vel4ever)\
**Post date:** [July 10, 2012, 12:31pm UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/3 "2012-07-10T12:31:10Z")

</div>

Thank you for your suggestion. Is there any replacement command for %N. Also i need to get the first six decimal points only. Please help.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 10, 2012, 1:18pm UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/4 "2012-07-10T13:18:00Z")

</div>

It depends. What's your system?

---

<div class="post-metadata">

**Author:** ![vel4ever](https://community.unix.com/user_avatar/community.unix.com/vel4ever/32/7615_2.png) [@vel4ever](https://community.unix.com/u/vel4ever)\
**Post date:** [July 12, 2012, 2:57am UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/5 "2012-07-12T02:57:24Z")

</div>

Linux

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [July 12, 2012, 9:42am UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/6 "2012-07-12T09:42:47Z")

</div>

Then you are fine. %N is available to you as Linux uses GNU date by default.

---

<div class="post-metadata">

**Author:** ![vel4ever](https://community.unix.com/user_avatar/community.unix.com/vel4ever/32/7615_2.png) [@vel4ever](https://community.unix.com/u/vel4ever)\
**Post date:** [July 13, 2012, 12:55am UTC](https://community.unix.com/t/xml-datetime-format-in-shell-script/313256/7 "2012-07-13T00:55:14Z")

</div>

Thank you!
