|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
how can I convert this; Date: DD/MM/YYYY to this; ????????? is it possible? [ 10-19-2001: Message edited by: jeologic ]
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
hmmm... I wrote something, but not sure about anything... just tested this; I get a 8 month error I dont know the exact way to do this and couldnt find it [ 10-19-2001: Message edited by: jeologic ]
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
[ 10-19-2001: Message edited by: Dave_L ]
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
Thank you soooo much Dave 
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
|
|
|
|
Joined: Mar 2000
Posts: 21,079 Likes: 3
I type Like navaho
|
I type Like navaho
Joined: Mar 2000
Posts: 21,079 Likes: 3 |
Originally posted by Dave_L: #!/usr/bin/perl -w
use strict;
use Time::Local();
# test data my $ddmmyy = '19-10-2001'; my $hhmm = '21:57';
# convert my ($mday,$mon,$year) = split '-' => $ddmmyy; my ($hours,$min) = split ':' => $hhmm; my $sec = 0; my $time = Time::Local::timelocal($sec,$min,$hours,$mday,$mon-1,$year); print $time, "n";
# for checking (result should agree with $ddmmyy, $hhmm) print scalar(localtime($time)), "n"; How would you write this to &OpenFileAsArray and convert $linearray[5] 's data from $ddmmyy to unix time format?
|
|
|
|
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
|
Admin Emeritus
Joined: Jan 2000
Posts: 5,073 |
Make a Julian date out of it (jday or whatever it's called), then use JulianToEpoch or whatever it's called. So long since I've looked at the UBB6 source...
UBB.classic: Love it or hate it, it was mine.
|
|
|
|
Joined: Mar 2000
Posts: 21,079 Likes: 3
I type Like navaho
|
I type Like navaho
Joined: Mar 2000
Posts: 21,079 Likes: 3 |
Thank you, my data is written as : 18-Jan-01 It looks like the Julian date format of that would be: January 18, 2001 Is that right? Hmm.. I think that's actually gregorian date format, not julian. My time data is more the European Standard style
|
|
|
|
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
|
Admin Emeritus
Joined: Jan 2000
Posts: 5,073 |
No, I mean, use the UBB's Julian routines to unmunge the dates into something reasonable.
UBB.classic: Love it or hate it, it was mine.
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
Originally posted by AllenAyres:
My time data is more the European Standard style
Which is the best here is a sub I've modified from one of my codes: my $unix = allen('18-Jan-01') || die "can't convert!";
print scalar localtime $unix;
sub allen { require POSIX; my $param = shift || die "No date input specified!"; my($mday, $month, $year) = split /-/, $param; $year += 100 if $year < 70; # is 70..99 or 00..05 my $c = 0; # index counter my %months = map{ $_ => $c++} qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $month = $months{$month}; # these are unnecessary, but they define what the parameters are my($hour, $min, $sec, $wday) = (0,0,0,0); my $timestamp = POSIX::mktime($sec, $min, $hour, $mday, $month, $year, $wday, 0, -1); return $timestamp; }
|
|
|
|
Joined: Mar 2000
Posts: 21,079 Likes: 3
I type Like navaho
|
I type Like navaho
Joined: Mar 2000
Posts: 21,079 Likes: 3 |
Sweet! I can stay home this dreary weekend and work on this then, thank you 
|
|
|
|
Joined: Mar 2000
Posts: 21,079 Likes: 3
I type Like navaho
|
I type Like navaho
Joined: Mar 2000
Posts: 21,079 Likes: 3 |
This is what I have so far. The first sub is the one that opens the data, the second one is what's supposed to convert the time: ###########################################################################################
sub ConvertTime{
&RequireUserLogin(1); my @profile = &verify_id_num($username, $password, $user_number); unless ($profile[8] eq 'Administrator' or 'Moderator') { &StandardHTML2("$vars_wordlets_err{no_access}"); exit;}
my @datafile = &OpenFileAsArray("$vars_config{NonCGIPath}/links/links_data.cgi"); foreach $line(@datafile){ chomp $line; @linearray = split(/||/,$line); my $unix = &allen('$linearray[5]') || die "can't convert!";
print scalar localtime $unix; } &WriteFileAsArray("$vars_config{NonCGIPath}/links/links_data.cgi",@datafile);
##output &StandardHTML("Time Format Converted - <a href="links_importer.cgi">Return to Import Script</a>"); }
###########################################################################################
sub allen { require POSIX; my $param = shift || die "No date input specified!"; my($mday, $month, $year) = split /-/, $param; $year += 100 if $year < 70; # is 70..99 or 00..05 my $c = 0; # index counter my %months = map{ $_ => $c++} qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $month = $months{$month}; # these are unnecessary, but they define what the parameters are my($hour, $min, $sec, $wday) = (0,0,0,0); my $timestamp = POSIX::mktime($sec, $min, $hour, $mday, $month, $year, $wday, 0, -1); return $timestamp; } ########################################################################################### It really isn't doing anything yet. linearray[5] is where the time is stored in the data 
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
you are saying single quotes don't interpolate  You have to use double quotes: Try this one: foreach $line(@datafile){ chomp $line; @linearray = split(/||/,$line); $linearray[5] = &allen("$linearray[5]") || die "can't convert!"; }
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
theory not always works :rolleyes: this should do the trick: foreach my $line (@datafile){ chomp $line; my @linearray = split(/||/,$line); $linearray[5] = allen($linearray[5]) || die "can't convert!"; $line = join '||', @linearray; }
|
|
|
|
Joined: Mar 2000
Posts: 21,079 Likes: 3
I type Like navaho
|
I type Like navaho
Joined: Mar 2000
Posts: 21,079 Likes: 3 |
muchas gracias 
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 254
Joined: January 2000
|
|
Forums63
Topics37,575
Posts293,930
Members13,823
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|