CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Date Format in MySQL

Print topic Send  topic

Author Message
Paul
Posted: 02/18/2002, 5:59 AM

I found the following response in the Forum, but would like the code in .asp can anyone help? using UK date format for user entry dd-mm-yyyy

Rgds

Paul

----------------
Previous Posting
----------------

You can let users to input date in e.g. German format and then format it to MySQL date format. It’d be helpful to add JavaScript to form Footer in order to force user to enter date in particular mask, e.g. in DD.MM.YYYY format
Then you define BeforeInsert and BeforeUpdate events with the code like below to convert date to MySQL format:
$day = substr($flddate_field, 0, 2);
$month = substr($flddate_field, 3, 2);
$year = substr($flddate_field, 6, 4);
$flddate_field = $year . "-" . $month . "-" .$day;

To display date field in format you want (e.g. in DD.MM.YYYY format) you should create the following BeforeShow event (note it uses some MySQL date functions so it is solution for MySQL only):

$day = dLookUp("table_name", "DATE_FORMAT(date_field, '%e')", "id_field = ".$fld id_field);
$month = dLookUp("table_name ", "MONTH(date_field)", " id_field = ".$fld id_field);
$year = dLookUp("table_name ", "YEAR(date_field)", " id_field = ".$fld id_field);
$flddate_field = date("d-m-Y", mktime(0,0,0, $month, $day, $year));
Nicole
Posted: 02/18/2002, 6:07 AM

Paul,
here is ASP code for MySQl date format:
You can let users to input date in e.g. German format and then format it to MySQL date format. It’d be helpful to add JavaScript to form Footer in order to force user to enter date in particular mask, e.g. in DD.MM.YYYY format
Then you define BeforeInsert and BeforeUpdate events with the code like below to convert date to MySQL format:
day = mid(flddate_field, 1, 2)
month = mid(flddate_field, 4, 2)
year = mid(flddate_field, 7)
flddate_field = year & "-" & month & "-" & day
To display date field in format you want (e.g. in DD.MM.YYYY format) you should create the following BeforeShow event (note it uses some MySQL date functions so it is solution for MySQL only):
day = dLookUp("table_name", "DATE_FORMAT(date_field, '%e')", "id_field = " & fldid_field)
month = dLookUp("table_name ", "MONTH(date_field)", " id_field = "& fld id_field)
year = dLookUp("table_name ", "YEAR(date_field)", " id_field = "& fld id_field)
flddate_field = day & "/" & month & "/" & year.

You may also refer to the article "How to display dates in different formats" http://www.gotocode.com/art.asp?art_id=132&



Paul
Posted: 02/18/2002, 6:23 AM

Nicole

I entered these pieces of code but got this error:

>Error Type:
>Microsoft VBScript runtime (0x800A01F5)
>Illegal assignment: 'day'
Nicole
Posted: 02/18/2002, 6:50 AM

Hm.. looks like "day" is reserved word.
Try to use other variable names:
d = mid(flddate_field, 1, 2)
m = mid(flddate_field, 4, 2)
y = mid(flddate_field, 7)
flddate_field = y & "-" & m & "-" & d
Paul
Posted: 02/18/2002, 6:59 AM

Nicole

That seems to work fine now, one final thing which is probably me being picky but if i enter for example 18/02/2002
Paul
Posted: 02/18/2002, 6:59 AM

Nicole

That seems to work fine now, one final thing which is probably me being picky but if i enter for example 18/02/2002
Paul
Posted: 02/18/2002, 6:59 AM

Nicole

That seems to work fine now, one final thing which is probably me being picky but if i enter for example 18/02/2002 it saves fine but then when i access the file again it displays as 18/2/2002

is there anyway i can preserve the 0 and have it display 18/02/2002?

Paul
Posted: 02/18/2002, 7:14 AM

Nicole,

I've found a problem with this code, when i enter a date it works fine, and then when i click on the record to update it displays fine, but if i make any alterations to this record and press update, the date is changed once again.

e.g. if i enter the date 18/02/2002 it will then display as 18/2/2002 and then if i view it again it displays it as 2/2/2000 :-(

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.