Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Date null = 0000-00-00

Quote Reply
Date null = 0000-00-00
I want to get rid of displaying 0000-00-00 if date value is left unfilled.

On original add form, it shows fine ie blank textbox, but when I submit, it and then later try to modify it, it shows 0000-00-00 on text box.



How do I get rid of these 0's.

Do I need to add clobal template maybe? Or is it just setting up the values. Currently I have set date box to NULL in MySQL.

Thx



On original add recored the textbox value is set to: value=""

And on modify form is set to: value="<%Birthday%>"

Last edited by:

Suomi: Mar 17, 2002, 10:12 AM
Quote Reply
Re: [Suomi] Date null = 0000-00-00 In reply to
Hi,

You should create a Global template, take a look at the script below:

sub {
my $tags = shift;
my $values = $tags->{values};
$value->{date_field_name} = '' if ($value->{date_field_name} eq '0000-00-00');
return;
}

TheStone.

B.
Quote Reply
Re: [TheStone] Date null = 0000-00-00 In reply to
Thanks TheStone

I tried and added global template, and named it "format_empty_name"

Pasted all your code in to it.

Added <%format_empty_name%> tag on my modify template.

and I got this:

Unable to compile 'format_empty_date'. Reason: Global symbol "$value" requires explicit package name at (eval 15) line 4.
Global symbol "$value" requires explicit package name at (eval 15) line 4.

What did I miss here? (btw I have about 50 date fields total, that this needs to be applied)
Quote Reply
Re: [Suomi] Date null = 0000-00-00 In reply to
oops...

Change: $value->{date_field_name} = '' if ($value->{date_field_name} eq '0000-00-00');
To: $values->{date_field_name} = '' if ($values->{date_field_name} eq '0000-00-00');

B.
Quote Reply
Re: [TheStone] Date null = 0000-00-00 In reply to
No errors Cool, but still 0000-00-00 shows.

Do I need to change "date_field_name" for field name of the date field? (Tried that too, but 0's still shows)

I have around 50 such fields...?



I think the problem is value... its stored as a "null" in database, but it still shows 0000-00-00 when viewing modify form.

Thanks

Last edited by:

Suomi: Mar 18, 2002, 10:31 AM
Quote Reply
Re: [Suomi] Date null = 0000-00-00 In reply to
Put <%GT::Template::dump%> anywhere on your template it will dump the current tags available. And then change your script.

B.
Quote Reply
Re: [TheStone] Date null = 0000-00-00 In reply to
Ok I checked and tested but looks like the script is doing nothing.

I changed and tested it like this:

sub {
my $tags = shift;
my $values = $tags->{values};
$values->{DateOfBirth} = '1969-11-11' if ($values->{DateOfBirth} eq '1970-12-12');
return;
}



My understanding that above global template would change the value of textbox named DateOfBirth to 1969-11-11 if value is currently stored as 1970-12-12.

Am I correct? I tried it, and nothing happened. Am I still missing something from the global template? I used the dump feature, and saw that format_empty_date was available.

Thanks again for helping me with this.
Quote Reply
Re: [Suomi] Date null = 0000-00-00 In reply to
Could you send me admin info (link, user, password) via private message. I'll take a look at it.

B.
Quote Reply
Re: [Suomi] Date null = 0000-00-00 In reply to
You need to change:

return;

to

return $values->{DateOfBirth};

...I think.

Last edited by:

Paul: Mar 18, 2002, 1:03 PM
Quote Reply
Re: [Paul] Date null = 0000-00-00 In reply to
Thanks we are getting closer.(Thx for trying to help me out)

I changed last line to: return $values->{DateOfBirth};

And now I can see that the value has changed (But the purpose of this is not to display the value as a text, but as a textfield(which did not get updated)

So I assume I have to add update command somewhere...

The original script above works fine when using sample database, but I have modified my database, and not using <%Dbsql::HTML::generate_modify_form%>.

So I think I am missing something what they have in <%Dbsql::HTML::generate_modify_form%>.

but what?

Thx
Quote Reply
Re: [Suomi] Date null = 0000-00-00 In reply to
I read this post with interest because I wondered about this a few days ago myself.

My solution is probably not the most elegant or the "right" way to do it, but it works. I just used conditional statements within the input tags for my date fields on the add/modify record form.

Example:
<input type="text" name="date_field" value="<%if date_field == 0000-00-00%><%else%><%date_field%><%endif%>">

Hope this helps!
Quote Reply
Re: [Halito] Date null = 0000-00-00 In reply to
Thanks for reply, Stone told me the same thing, and thats what I end up using...

Cant wait till they release next version... I think I was missing few files... :)
Quote Reply
Re: [Halito] Date null = 0000-00-00 In reply to
Okay so I'm having a some what similar problem. I imported my flatfile DBMan database to dbman SQL and all of my fields are coming up as 0000-00-00. My dbman date format is actually MMM-DD-YYYY. So it differs from the sql date version. I tried changing the date format in GT/Date.pm, but it made no difference. Does anyone have any idea where else I need to change the date format to get this working?

Thanks! Smile
Reena