Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

How can I change the date??????

Quote Reply
How can I change the date??????
Here is my problem: I'm using the LinksSQL for a french search engine. The problem is that the date look like 01/25/00, when I need it in 25/01/00. How can I make the changes????????????

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Like Links 2.0, you need to edit the sub _unix_to_date routine in the DBSQL.pm file.

See the following codes:

Code:

return "$year-$mon-$day";


Change it to the following:

Code:

return "$day-$mon-$year";


You will also need to edit the sub convert_date routine to show this output in the Import.pl file and then re-upload your Links 2.0 database AFTER you EMPTY your current tables to make sure that the dates are converted properly.

Regards,

Eliot

Quote Reply
Re: How can I change the date?????? In reply to
thanx!!!

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
You're welcome.

Regards,

Eliot

Quote Reply
Re: How can I change the date?????? In reply to
FWIW, this is a good place to say it, MySQL will accept dates in a limited number of input formats, but internally, it stores _ALL_ dates as "YYYY-MM-DD HH:MM:SS", how much of that is stored depends on the field definition (length).

The skinny is, that every date called FROM the MYSQL database will have the output format (or internal representation of) YYYY-MM-DD no matter what format you put it in with. It's up to you to format the date in whatever output format you want.

If the "date" field is expanded to include the HH:MM:SS field, I believe they are set to 00:00:00.

Here is the section of the MySQL manual on DATE and DATETIME variables. I use this all the time, so it may help others:

http://www.mysql.com/...erence.html#DATETIME

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: How can I change the date?????? In reply to
I tried what you said Anthro, but every time I try to add a link with the new format, it shows:
Add_Date (Invalid format)
Mod_Date (Invalid format)
Date_Checked (Invalid format)
How come????

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Your .def file has a data-mask (a regex) that defines what the data looks like.

You can look at it in the Admin/Table Edit/Update area.

The date mask is set to accept yyyy-mm-dd by default. If you are changing that, you need to change the valid mask. ^\d{4}\-\d{2}\-\d{2}$

That means it's looking for a string starting with 4 digits, followed by a '-', then 2 digits followed by a '-' and ending with 2 digits. If you change the format, it won't pass the validation test when a record is edited or saved. This is a _LINKS_ thing, not a MySQL thing, per se.



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: How can I change the date?????? In reply to
hi,
thanx for your response..... But now, I'm having a new problem...grrrrrrrrr. When I add a link to the database, via the form, it like this: "26-07-2000". After I've hitten "add links", the date becomes: "2026-07-20". What did I do wron this time?????????

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
PLEASE PLEASE HELP!!!!!

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Let your fingers from the sql :-)
Everything you need is to format the data while giving it out:

sub site_html_link {
...
($rec->{'isPopular'} eq 'Yes') ? ($rec->{'isPopular'} = 1) : (delete $rec->{'isPopular'});

Add now::::

##--## 4.0 Tags für Datumsausgabe
$rec->{Date_Short} = &convert_date_short ($rec->{Add_Date});
$rec->{Date_Long} = &convert_date_long ($rec->{Add_Date});
$rec->{Date_Digit} = &convert_date_digit ($rec->{Add_Date});
##--##
and the new subs at the end of the file:

##--## 4.1 Convert Date LONG
sub convert_date_long {
# ---------------------------------------
my $in = shift;
my %months = qw!1 Januar 2 Februar 3 März 4 April 5 Mai 6 Juni 7 Juli 8 August 9 September 10 Oktober 11 November 12 Dezember!;
my ($year, $mon, $day) = split /-/, $in;
return "$day. $months{int $mon} $year";
}

##--## 4.2 Convert Date SHORT
sub convert_date_short {
# ---------------------------------------
my $in = shift;
my %months = qw!1 Jan. 2 Feb. 3 Mrz. 4 Apr. 5 Mai 6 Juni 7 Juli 8 Aug. 9 Sep. 10 Okt. 11 Nov. 12 Dez.!;
my ($year, $mon, $day) = split /-/, $in;
return "$day. $months{int $mon} $year";
}

##--## 4.3 Convert Date DIGIT
sub convert_date_digit {
# ---------------------------------------
my $in = shift;
my %months = qw!1 01 2 02 3 03 4 04 5 05 6 06 7 07 8 08 9 09 10 10 11 11 12 12!;
my ($year, $mon, $day) = split /-/, $in;
return "$day.$months{int $mon}.$year";
}


That´s it and one day i will be a real perler, but not in this century :-)

Robert

Quote Reply
Re: How can I change the date?????? In reply to
thanx for your response Robert, I added what you said in HTML_Template.pm, but nothing was changed.... Why????


theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
PLease help!!!

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
please...

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
You need to start using the new date now that you added that. Replace <%Add_Date%> with <%Date_Short%> or whatever format you want.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: How can I change the date?????? In reply to
thanx Alex!!!
So the trick worked for links added dates.... But what should I change to make it work for the last update???
thanx again,

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Same concept...you use $rec->{Mod_Date} RATHER than $rec->{Add_Date}.

Do you understand?

"Thinking out of the box (codes) is fun and effective."

Regards,

Eliot

Quote Reply
Re: How can I change the date?????? In reply to
No not really... When I talk about update I think about the one on the categories, and homepage...
Thanx again,

theuls


---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Okay...Again...Same concept...you have to change the reference for the date value in the globals section in the HTML_Templates.pm file!

Regards,

Eliot

Quote Reply
Re: How can I change the date?????? In reply to
OK Anthro... So normaly, I should put this line somewhere in HTML_Templates.pm :
$rec->{Date_Short} = &convert_date_short ($rec->{Date});
and in footer?txt, I should put this tag <%Date_Short%>
Right??? But where exactly in HTML_Templates.pm???
thanx for your time,

julien

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Search for "date" in the %GLOBALS hash in the HTML_Templates.pm file! Then change get_date to &convert_date_short!

Regards,

Eliot Lee

Quote Reply
Re: How can I change the date?????? In reply to
I know Eliot that your soon going to kill me.... But still, it isn't working...
I did this change:
date => \&Links::DBSQL::&convert_date_digit(),
and now the update day is shown as following:
 - 03:19:02
Why ????


theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
please help,

theuls

---------------------------------
surfootball.com your soccer index
Quote Reply
Re: How can I change the date?????? In reply to
Ya know it takes some time to respond to Threads...Posting numerous "please help" messages in a twelve hour period is annoying...Sorry.

Anyway...Okay...what you have to do is leave the date => \&Links::DBSQL::get_date,. Then you have to edit the sub get_date in the DBSQL.pm module.

Like the following:

Code:

sub get_date {
# ---------------------------------------------------------------
# Return todays date (self may or may not be an object).
#
my $self = shift;
ref $self ? return &_unix_to_page_date (@_) : return &_unix_to_page_date ($self);
}


Then add a subroutine called sub _unix_to_page_date in the same module file:

Code:

sub _unix_to_page_date {
# --------------------------------------------------------
# Private method to translate a unix time value into a date.
#
my $time = shift || time;
($time =~ /^\d+$/) or ($time = time);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime $time;
$year = $year + 1900;
$mon++;
my %months = qw!01 January 02 February 03 March 04 April 05 May 06 June 07 July 08 August 09 September 10 October 11 November 12 December!;
($mon < 10) and ($mon = "0" . int $mon); ($day < 10) and ($day = "0" . int $day);
return "$months{$mon} $day, $year";
}


You can edit the @months array and also the format of the date by editing the return line. Unfortunately, referencing the convert_date subs you created will not work because of the int function.

Regards,

Eliot