# Help with date in AIX

**URL:** <https://community.unix.com/t/help-with-date-in-aix/390880>\
**Category:** AIX\
**Created:** [May 2, 2023, 8:18pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880 "2023-05-02T20:18:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![egvghost](https://community.unix.com/user_avatar/community.unix.com/egvghost/32/21661_2.png) [@egvghost](https://community.unix.com/u/egvghost)\
**Post date:** [May 2, 2023, 8:18pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/1 "2023-05-02T20:18:49Z")

</div>

Hi there...

I have this perl command which convert an epoch timestamp into human readable date:

```plaintext
perl -i -lpe 's/([\d]{10})/localtime $1/eg;'

```

which is providing this output:

`Mon May 1 00:25:28 2023`

How can I modify the perl command **(without using strftime**) to format the date as "%Y-%0m-%0d HH:MM:SS"?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [May 2, 2023, 8:42pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/2 "2023-05-02T20:42:02Z")

</div>

I'm not really a perl guru, but:

```bash
$ perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime; printf "%04d-%02d-%02d %02d:%02d:%02d\n", $YY + 1900 , $MM +1 , $DD, $hh, $mm, $ss'
2023-05-02 20:33:19

```

Or with AiX's `ksh93`:

```bash
$ echo $0
ksh93
$ printf "%(%Y-%m-%d %H:%M:%S)T\n" now
2023-05-02 20:37:11

```

And probably many-many more ways to do it...

---

<div class="post-metadata">

**Author:** ![egvghost](https://community.unix.com/user_avatar/community.unix.com/egvghost/32/21661_2.png) [@egvghost](https://community.unix.com/u/egvghost)\
**Post date:** [May 2, 2023, 10:37pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/3 "2023-05-02T22:37:21Z")

</div>

Thanks, I've found this other way working on this limited Aix endpoint:

```plaintext
perl -i -MPOSIX -lpe 's/([\d]{10})/POSIX::strftime("%Y-%0m-%0d %T", localtime $1)/eg;' "$FILE"

```

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [May 2, 2023, 10:39pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/4 "2023-05-02T22:39:37Z")

</div>

I thought you said "**(without using strftime**)", but either way - congrats!

---

<div class="post-metadata">

**Author:** ![egvghost](https://community.unix.com/user_avatar/community.unix.com/egvghost/32/21661_2.png) [@egvghost](https://community.unix.com/u/egvghost)\
**Post date:** [May 3, 2023, 12:15pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/5 "2023-05-03T12:15:33Z")

</div>

you are right, I did.. that's because when I've tried a command using strftime before I got an error message saying strftime was not found. Anyway, this one worked. Thanks.

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/6_22734026db12803ebb3e059622ac3534.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [May 3, 2023, 1:17pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/6 "2023-05-03T13:17:50Z")

</div>

Yes, strftime is from the POSIX module.  
Without POSIX::strftime perl starts faster:

```plaintext
perl -i -lpe 's/([\d]{10})/{ ($ss, $mm, $hh, $DD, $MM, $YY) = localtime $1; sprintf "%04d-%02d-%02d %02d:%02d:%02d", $YY + 1900 , $MM +1 , $DD, $hh, $mm, $ss; }/eg;' "$FILE"

```

Note: the `g` modifier looks for further matches in the current line and would substitute them. For example, a line  
`1683120629 123456789012 sometext`  
will become  
`2023-05-03 15:30:29 2009-02-14 01:31:3012 sometext`

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [February 27, 2024, 1:18pm UTC](https://community.unix.com/t/help-with-date-in-aix/390880/7 "2024-02-27T13:18:41Z")

</div>

Closed on February 27, 2024, 1:18pm UTC

This topic was automatically closed 300 days after the last reply. New replies are no longer allowed.
