You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Date with hour, min, sec: echo dh_handletimestamp("2023-01-01 01:00:00");
returns: 1672552800
# enter PHP in terminal mode
php -a
function dh_handletimestamp($ts) {
// don't do date_received as this is a field and is handled there
if ( ($ts <> '') and !($ts == NULL)) {
$orig = $ts;
// if a valid unix epoch style timestamp has been submitted
// this next will try to convert a string
if (!( !is_numeric($ts) ? (ctype_digit($ts)) : true ) ) {
// not a valid unix timestamp, so try to convert from some date format
$ts = strtotime($ts);
//drupal_set_message("Converted $orig to Epoch: " . $ts);
} else {
// valid unix timestamp submitted, proceed without changing
}
}
return $ts;
}
echo dh_handletimestamp("2023-01-01");
# output: 1672549200
Bash date command
may need us to give it timezone, as it differs in output
date -d '2023-01-01' +'%s'
yields: 1672531200
Gving a hour, mon sec:
TZ="America/New_York" date -d '2023-01-01 01:00:00' +'%s'
yields: 1672552800
We can povide a timezone context to the command which is the most direct way:
Overview
Code
Postgresql date
select extract(epoch from to_timestamp('2023-01-01 01:00:00','YYYY-MM-DD HH:MI:SS'))::int;
1672552800
PHP dh_handletimestamp
fgrep timezone /etc/php/7.4/apache2/php.ini
date.timezone = America/New_York
echo dh_handletimestamp("2023-01-01 01:00:00");
1672552800
Bash
date
commanddate -d '2023-01-01' +'%s'
1672531200
TZ="America/New_York" date -d '2023-01-01 01:00:00' +'%s'
1672552800
TZ="America/New_York" date -d '2023-01-01' +'%s'
1672549200
/etc/localtime
is a symbolic link to the desired timezone,/etc/localtime -> /usr/share/zoneinfo/Etc/UTC
TZ
option could be best.NLDAS2 Dates
The text was updated successfully, but these errors were encountered: