Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Command for delete parts of data?

Quote Reply
Command for delete parts of data?
Hi somehow I managed to add time for my data...
I have date created on my database with data like:
11/11/1987 0:00:
2/2/1998 0:00:0
As you can see this is just varchar column with size 15.

I Also have some data, that does not have date info at all.

What I want is to display just date, and no time (No time info available) and the data, that does not have date available, I want it be blank not 00-00-0000.(ie no data on column)

I tried setting column size to 10, but some info that has 1 digit months and 1 digit dates still displays 0 at the end of the date like:
1/1/1995 0
???
Is there a command that I could set, that would remove 0:00 at the end?


Last edited by:

Suomi: Dec 10, 2001, 10:42 AM
Quote Reply
Re: [Suomi] Command for delete parts of data? In reply to
Hi,

Why haven't you used Date data for that field? That should be better.
Anyway, you can use the scripts below:

1. create format_date subroutine in Global template:

sub {
my $field_name = shift;
my $tags = GT::Template->tags;
my $record = $tags->{results}[$tags->{row_num}-1];
my $value = $record->{$field_name};
require GT::Date;
$record->{$field_name} = GT::Date::date_transform($value,"%yyyy%-%mm%-%dd%","%mm%/%dd%/%yyyy%");
return;
}

2. Modify your search_results.html file (or *_results.html):

<%loop results%>
<%format_date("field_name")%>
<p><%Dbsql::HTML::generate_search_results%>
<%endloop%>

Cheers,
TheStone.

B.
Quote Reply
Re: [TheStone] Command for delete parts of data? In reply to
Ok I reupoaded everything, and before I did, I set up the date field.Wink

Ok now the sad partUnsure
My dates in my original database were like this:
10/7/2000
And now they look like this:
2010-07-20

Well any suggestions, how to correct this?
Quote Reply
Re: [TheStone] Command for delete parts of data? In reply to
Ok everything is working. Dates are correct now. I used the date field.

Now is there a way to display only Year and month from date field?

ie could I set up Mysql date field lenght and values something like yyyy/mm?

(Just like timestamp value)

I tried above and TheStone's example , and it did not work... I dont think it supposed to work anyhow, with this problem. Help please.

ThanksSmile
Quote Reply
Re: [Suomi] Command for delete parts of data? In reply to
Hi,

You can use:

require GT::Date;
my mydate = GT::Date::date_transform("2002-02-15","%yyyy%-%mm%-%dd%","%yyyy%/%mm%");

TheStone.


B.
Quote Reply
Re: [TheStone] Command for delete parts of data? In reply to
Thanks TheStone

hmm, where should I put this.. Global templates?

What is this current date for? 2002-02-15
Quote Reply
Re: [Suomi] Command for delete parts of data? In reply to
That's right :)

B.
Quote Reply
Re: [TheStone] Command for delete parts of data? In reply to
You are faster than a bullet Wink Thanks for quick replies.

This is what I did... (well one of them) I tried several variations of this.

But let me see if I understand you right:

This is what I added to Global templates: (On my working template set)

Quote:
sub {
my $field_name = shift;
my $tags = GT::Template->tags;
my $record = $tags->{results}[$tags->{row_num}-1];
my $value = $record->{$field_name};
require GT::Date;
my mydate = GT::Date::date_transform("2002-02-15","%yyyy%-%mm%-%dd%","%yyyy%/%mm%");
return;
}


And this is what I added to my search_result.html:

Code:
<%elseif address%>
<%loop results%>
<%format_date("field_name")%>
<%include address_detail.html%>
<%endloop%>


And I get this:

Unable to compile 'format_date'. Reason: No such class mydate at (eval 14) line 7, near ";
my mydate"
syntax error at (eval 14) line 7, near "my mydate ="

ThanksAngelic
Quote Reply
Re: [Suomi] Command for delete parts of data? In reply to
Hi,

Your script should be:

sub () {
my $tags = shift;
my $field_name = $tags->{field_name};
my $record = $tags->{results}[$tags->{row_num}-1];
my $value = $record->{$field_name};
require GT::Date;
$record->{$field_name} = GT::Date::date_transform($value,"%yyyy%-%mm%-%dd%","%yyyy%/%mm%");
return;
}

And the search_results.html:
....
<%loop results%>
<%set field_name = 'date_field_name'%>
<%format_date%>
....
<%endloop%>
...

That should work.

TheStone.

B.
Quote Reply
Re: [Suomi] Command for delete parts of data? In reply to
Do you mean $mydate instead of mydate? WinkCool