Forum Moderators: open

Message Too Old, No Replies

Sending a value for timestamp, what format?

         

csdude55

10:14 pm on Dec 19, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a TIMESTAMP column, with "on update current_timestamp()". I currently leave the field blank in all of my scripts, and just let MySQL take care of it.

But it's an irritant when I modify something in phpMyAdmin and it changes the timestamp when I didn't mean for it to, so I'd rather remove the "on update..." and insert a timestamp in Perl / PHP.

The question is, what format do I need to use?

In Perl, can I simply insert localtime(time)? Surely I don't have to manually format it to 2022-12-19 17:13:27 :-/

robzilla

11:16 pm on Dec 19, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just use CURRENT_TIMESTAMP() in your SQL queries in PHP/Perl?

[edited by: robzilla at 11:36 pm (utc) on Dec 19, 2022]

phranque

11:32 pm on Dec 19, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the format of a TIMESTAMP column is the 19 character string:
YYYY-MM-DD HH:MM:SS


to get this string in perl:
my ($sec,$min,$hour,$mday,$mon,$year) = localtime;
$year += 1900;
my $timestamp = "$year-$mon-$mday $hour:$min:$sec";

or
use POSIX qw(strftime);
my $timestamp = strftime "%F %X", localtime;