Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
how can I convert this;

Date: DD/MM/YYYY
Quote
quote:
to this;

Quote
quote:
?????????

is it possible?

[ 10-19-2001: Message edited by: jeologic ]

Sponsored Links
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 tipsy

I dont know the exact way to do this and couldnt find it frown

Code
code:

[ 10-19-2001: Message edited by: jeologic ]

Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Code
code:

[ 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 smile

Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
smile

Sponsored Links
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
Quote
Originally posted by Dave_L:

Code
#!/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?


- Allen wavey
- What Drives You?
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. smile

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. smash

My time data is more the European Standard style


- Allen wavey
- What Drives You?
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
Quote
Originally posted by AllenAyres:

My time data is more the European Standard style
Which is the best wink

here is a sub I've modified from one of my codes:

Code
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;
}

Sponsored Links
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 thumbsup


- Allen wavey
- What Drives 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:

Code
###########################################################################################

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]') &#0124;&#0124; 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 &#0124;&#0124; 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 smile


- Allen wavey
- What Drives You?
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
you are saying
Code
&allen('$linearray[5]')
single quotes don't interpolate smile You have to use double quotes:
Code
&allen("$linearray[5]")
Try this one:

Code
	foreach $line(@datafile){
chomp $line;
@linearray = split(/||/,$line);
$linearray[5] = &allen("$linearray[5]") &#0124;&#0124; 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:

Code
foreach my $line (@datafile){
chomp $line;
my @linearray = split(/||/,$line);
$linearray[5] = allen($linearray[5]) &#0124;&#0124; die "can't convert!";
$line = join '&#0124;&#0124;', @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 thumbsup


- Allen wavey
- What Drives You?

Link Copied to Clipboard
Donate Today!
Donate via PayPal

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.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Ruben Rocha
Ruben Rocha
Lutz,FL,USA
Posts: 254
Joined: January 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)