Gossamer Forum
Quote Reply
Date and Time format
Hi,

I use the below Global to fetch the date and time of the newest link added. I have a custom Field Add_Time that contains the date added in the format 0000-00-00 00:00:00 (like Date Checked) - and want to output the date in the same form as defined in date_user_format - but I want to add the time like HH:MM and tried several things but it does not seem to work??

If I remove the GT::Date::date_transform ... I get the time - but in the 0000-00-00 00:00:00 format - I want it as:


%dddd%, %mmmm% %dd% - %yyyy% at %hh%:%mm%


Any ideas?

Klaus


sub {
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 1');
$sth = $search_db->select ( { isValidated => 'Yes' });
while (my $link = $sth->fetchrow_hashref) {
$link->{Add_Time} = GT::Date::date_transform ($link->{Add_Time}, $CFG->{date_db_format}, $CFG->{date_user_format});
$output.=qq|$link->{Add_Time}|;
}
return $output;
}

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date and Time format In reply to
Try something like
Code:
$link->{Add_Time} = GT::Date::date_transform ($link->{Add_Time}, "%yyyy%-%mm%-%dd% %HH%-%MM%-%ss%", "%dddd%, %mmmm% %dd% - %yyyy% at %hh%:%MM%" );
The problem is the 'Add_Time' is not in date_db_format, which is just %yyyy%-%mm%-%dd%.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Date and Time format In reply to
Thanks Yogi - worked :-)

Klaus

If anyone is interested, the final global is:

sub {
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 1');
$sth = $search_db->select ( { isValidated => 'Yes' });
while (my $link = $sth->fetchrow_hashref) {
$link->{Add_Time} = GT::Date::date_transform ($link->{Add_Time}, "%yyyy%-%mm%-%dd% %HH%:%MM%:%ss%", "%dddd%, %mmmm% %dd% - %yyyy% at %hh%:%MM%" );
$output.=qq|$link->{Add_Time}|;
}
return $output;
}

http://www.ameinfo.com
Quote Reply
Re: [yogi] Date and Time format In reply to
Another thing - how can I then output how long it has been since last updates? ie compare to <%date%><%time%> and output:



hours, minutes (but only those applicable) so only "7 minutes ago" for example if hours are equal 0.

If hours then "4 hours and 22 minutes ago"

If days (more than 24 hours) then output the normal $link Add_Time...

Cheers

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date and Time format In reply to
hey how did u create the Add_Time field so that it'll input the right date and time (0000-00-00 00:00:00) when user or admin add links to database?
Quote Reply
Re: [xpert] Date and Time format In reply to
I had that done by GT as part of importing my data which contains the time an article was added and I did not want to mess with Add_Date (not recommended in this Forum) - so I have it as a seperate field that I use for sorting.

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date and Time format In reply to
I have a field for each link named Add_Time in the format:

yyyy-mm-dd hh:mm:ss

- how can I get the number of hours and minutes between current time and the Add_Time - only if the date is the same - otherwise just output the date

Any suggestions?

Klaus

http://www.ameinfo.com