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

Date Validation Format Question

Quote Reply
Date Validation Format Question
Hello,

I have added a date field to the links db and I want to validate the field in the following format:
Jan 1, 2000

Currently for this format: 2000-04-08
is ^\d{4}\-\d{2}\-\d{2}$

Any ideas on this, and if anyone can explain the code and how it works so that I can know for future reference or similar problems.

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City
ICQ: 44147229





Quote Reply
Re: Date Validation Format Question In reply to
Hello,

I want the date to look like this:

Jan 1, 2000

------------------
James L. Murray
PaintballCity.com
The Yahoo of Paintball
www.paintballcity.com
AIM: Paintball City
ICQ: 44147229





Quote Reply
Re: Date Validation Format Question In reply to
Before you make yourself crazy....

MySQL can accept dates in many formats, but it will STORE and OUTPUT in only one --- YYYY-MM-DD

If you are trying to do something else, let me know. If you want to date to look different, you need to make your own date output routine.

Quote Reply
Re: Date Validation Format Question In reply to
You'd have to make a date routine that would re-format the date that is passed to the link.html

Basically you want to assign the

$rec->{'Add_Date'} = &new_date_format

where

sub new_date_format

is the translation of the date the way you want it.

When $rec is passed, the date will be in the new format.








[This message has been edited by pugdog (edited April 11, 2000).]
Quote Reply
Re: Date Validation Format Question In reply to
 
Quote:
MySQL can accept dates in many formats

Actually it only likes YYYY-MM-DD format and won't work with anything else (usually you end up with 0000-00-00 as your date if you try it).

Your right though, go into site_html_link in HTML_Templates.pm and add:

$rec->{Add_Date} = &convert_date ($rec->{Add_Date});

and then add a subroutine:

sub convert_date {
.. convert from YYYY-MM-DD to MMM DD, YYYY
}

Cheers,

Alex
Quote Reply
Re: Date Validation Format Question In reply to
Splitting hairs -- MySQL can _accept_ dates in many formats, but it stores them in only one: yyyy-mm-dd hh:mm:ss

This is why you can input a date such as yy-mm-dd and yymmdd or yyyymmdd but it comes out at 1999-04-07

The input routines are better, I guess to allow various data imports, but the output was standardized to one format.

Interestingly, if you study the date/time formats carefully, by using one format, and one set of logic, you can do some tricky things with them, and MySQL will change the date format based on the field definition!

Check out http://www.mysql.com/...hp3?section=DATETIME for some interesting stuff.

The new MySQL interactive manual (written apparantly in PHP) is pretty cool! It's a lot nicer than the old one.

Quote Reply
Re: Date Validation Format Question In reply to
Your right, however when you say many date formats, I'm used to things like Access or MS SQL which can accept:

Apr 15, 1996
15 Apr 1996
15 April 1996
1996-15-04
1996-04-15
04.15.96
04/15/96
etc.

Whereas mysql only accepts:

1996-04-15
96-04-15

or using someother delimiter besides a dash. Can't do much else with it unfortunately. =)

Cheers,

Alex