Gossamer Forum
Home : Products : DBMan : Customization :

date and time

Quote Reply
date and time
Is it possible to get the date and time to be displayed under a one field
Or do i have to have 2 fields .. one for 'date' and one for 'time'??

Quote Reply
Re: date and time In reply to
This thread referenced that topic, but you may need to find the previous thread by NgtCrwlr for the date/time modification he used.


Thread reference: 000730
Subject More Unix Date ???
NgtCrwlr - 17-Aug-99 03:49 AM

You can also check the FAQ referenced below under dates and also under syntax.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: date and time In reply to
Cant find the thread you are talking about ...
can you post a link or some code??

I would like to get a date and time in one field .. is it possible??

Quote Reply
Re: date and time In reply to
What format do you want the date and time to be in? For example, at this moment, it is
14-Jul-2000 03:14:23

Is that how you would like your date and time to appear?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: date and time In reply to
I did provide the thread reference above, after searching myself here is the full url:

http://www.gossamer-threads.com/perl/forum/showthreaded.pl?Cat=&Board=DBCust&Number=4157&Search=true&Forum=DBCust&Words=More Unix Date ???&Match=Entire Phrase&Searchpage=0&Limit=25&Old=1year

After searching I also found this thread which is somewhat continued from the one above.

http://www.gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=DBCust&Number=93676&page=&view=&sb=&vc=1

You may find other threads by searching ALL posts for "time" .

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: date and time In reply to
July 15, 2000 1:53am

would be the date and time look im after
So am I able to get this into a "Last Modified" field or does it have to go across 2 fields??

Quote Reply
Re: date and time In reply to
You can put it in one field if you want to.

Code:

sub get_date {
# --------------------------------------------------------
# Returns the date in the format "Mmmm dd, yyyy hh:mm am/pm".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.
my ($time) = @_;
($time) || ($time = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
 
# Expand the month names below
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
 
$year = $year + 1900;
 
if ($hour == 12) { $ampm = "p.m." }
elsif ($hour == 0) { $hour = 12; $ampm = "a.m."; }
elsif ($hour <12) { $ampm = "a.m." }
else { $hour -=12; $ampm = "p.m." }

($min < 10) and ($min = "0" . $min)
 
return "$months[$mon], $day $year $hour:$min $ampm";
}
Code:

sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
  
# Expand the month names below
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
  
my ($time);
my ($mon, $day, $year, $time, $ampm) = split(/ /, $date);
$day =~ s/,//;
my ($hour, $min) = split(/:/, $time);
if (($hour == 12) && ($ampm eq "a.m.")) { $hour == 0; }
elsif (($hour<12) && ($ampm eq "p.m.")) { $hour +=12; }
  
unless ($day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
 
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$min = int($min); $hour = int($hour);
$time = timelocal(0,$min,$hour,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: date and time In reply to
Im not sure why but with the code added above and the month modify stuff done i get this as my date

Jan, 1 1970 11:0 a.m.

In my html file i have

if ($in{'modify_form_record'}) { $rec{'Last Date Modified'} = &get_date;}
if ($in{'add_form'}) { $rec{'Last Date Modified'} = &get_date;}

and

if ($per_admin) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="240"><$font_color>Last Date Modified:</FONT></TD>
<TD VALIGN="TOP" WIDTH="610"> <INPUT TYPE="TEXT" NAME="Last Date Modified" SIZE="20" VALUE="$rec{'Last Date Modified'}" MAXLENGTH="255"></TD></TR>
|;
}
else {
print qq|
<input type="hidden" NAME="Last Date Modified" VALUE="$rec{'Last Date Modified'}">
|;
}
print qq|
|;




Quote Reply
Re: date and time In reply to
I didn't think about that. There is an additional line in the original code above in green.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: date and time In reply to
($min < 10) and ($min = "0" . $min)

seems to be a problem when i add this ... i get a blank page when i run the cgi file??

when i remove it .. it goes back to the original way


Quote Reply
Re: date and time In reply to
Okay. Let's try it this way:

Code:

if ($min < 10) {
$min = "0" . $min;
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: date and time In reply to
I still had errors ... so I decided to dive into the deep end and play with the code.
Few hours later this is what I came up with:

sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

if ($hour == 12) { $ampm = "PM" }
elsif ($hour == 0) { $hour = 12; $ampm = "AM"; }
elsif ($hour <12) { $ampm = "AM" }
else { $hour -=12; $ampm = "PM" }

return "$months[$mon], $day $year $hour:$min $ampm";
}


I couldnt figure out at first why this seemed to work ...
But we get the time from this line dont we?
(This is the only reason I can think that it works)

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());

This is all I added from your code:

if ($hour == 12) { $ampm = "PM" }
elsif ($hour == 0) { $hour = 12; $ampm = "AM"; }
elsif ($hour <12) { $ampm = "AM" }
else { $hour -=12; $ampm = "PM" }

return "$months[$mon], $day $year $hour:$min $ampm";

and modified slightly to get the AM and PM i was looking for.

Does this seem right to you JP ... Im hoping it is.
Thanx for ya help