Skip to main content
added 9 characters in body
Source Link
Stéphane Chazelas
  • 586.9k
  • 96
  • 1.1k
  • 1.7k

I am retrieving the following dates from aan IBM DB2 database:

  • 2022-04-12-08.22.28.940722
  • 2018-10-30-10.28.10.112309
  • 2022-04-07-14.13.19.426219

In my bash script I am writing them to a file (where the date is $lastlogintime):

echo -n " - Naam van gebruiker: $loginname - Laatste login: $lastlogintime" >> $LOGFILE

I want to save the date in another format, like this:

  • 10-2-2023 14:48:27
  • mm-dd-yyyy hh:mm:ss

What is the correct syntax for this?

I am retrieving the following dates from a database:

  • 2022-04-12-08.22.28.940722
  • 2018-10-30-10.28.10.112309
  • 2022-04-07-14.13.19.426219

In my bash script I am writing them to a file (where the date is $lastlogintime):

echo -n " - Naam van gebruiker: $loginname - Laatste login: $lastlogintime" >> $LOGFILE

I want to save the date in another format, like this:

  • 10-2-2023 14:48:27
  • mm-dd-yyyy hh:mm:ss

What is the correct syntax for this?

I am retrieving the following dates from an IBM DB2 database:

  • 2022-04-12-08.22.28.940722
  • 2018-10-30-10.28.10.112309
  • 2022-04-07-14.13.19.426219

In my bash script I am writing them to a file (where the date is $lastlogintime):

echo -n " - Naam van gebruiker: $loginname - Laatste login: $lastlogintime" >> $LOGFILE

I want to save the date in another format, like this:

  • 10-2-2023 14:48:27
  • mm-dd-yyyy hh:mm:ss

What is the correct syntax for this?

Source Link
Niek Jonkman
  • 243
  • 1
  • 2
  • 6

Format date to another date format in bash

I am retrieving the following dates from a database:

  • 2022-04-12-08.22.28.940722
  • 2018-10-30-10.28.10.112309
  • 2022-04-07-14.13.19.426219

In my bash script I am writing them to a file (where the date is $lastlogintime):

echo -n " - Naam van gebruiker: $loginname - Laatste login: $lastlogintime" >> $LOGFILE

I want to save the date in another format, like this:

  • 10-2-2023 14:48:27
  • mm-dd-yyyy hh:mm:ss

What is the correct syntax for this?