shaun
Junior Member
Posts: 2
Registered: 3/20/2003
Member Is Offline
|
| posted on 3/20/2003 at 01:35 PM |
|
|
Output format suitable for MySQL
hi,
is it possible to change the format that the calendar outputs to be suitable for MySQL DATE Type? i.e. YYYY-MM-DD.
Thanks for your help
|
|
|
nik
Posts:
Registered: 1/1/1970
Member Is Offline
|
| posted on 3/21/2003 at 08:13 AM |
|
|
You should just revise file calendar1.js.
To alter output format lines 69 and 70 ( cal_gen_date1 function body) are changed from:
(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "-"
+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
+ dt_datetime.getFullYear()
to:
dt_datetime.getFullYear() + "-" + (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) +
"-" + (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()
|
|
|
JugglingReferee
Junior Member
Posts: 3
Registered: 4/22/2003
Location: Waterloo, Ontario, Canada
Member Is Offline
|
| posted on 4/22/2003 at 02:28 AM |
|
|
I too an looking to populate a MySQL table with dates using this great script.
I noticed that once a field has been filled with data (from the script), and one clicks on the little calendar icon again, an error message pops up
saying that the date format is invalid and it does not let you continue to select a date.
If anyone has also fixed this, I would be greatful. In the meantime, I will try to fix it myself and will post the change if and when I complete
it.
Mike
|
|
|
nik
Posts:
Registered: 1/1/1970
Member Is Offline
|
| posted on 4/22/2003 at 08:44 AM |
|
|
Replace function cal_prs_date1(str_date) starting at 98 line by the following function:
function cal_prs_date1 (str_date) {
var arr_date = str_date.split('-');
if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.nFormat accepted is
dd-mm-yyyy.");
if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.nNo day of month value can be
found.");
if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.nAllowed values are
unsigned integers.");
if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.nNo month value can be found.");
if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.nAllowed values are
unsigned integers.");
if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.nNo year value can be found.");
if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid year value: '" + arr_date[0] + "'.nAllowed values are unsigned
integers.");
var dt_date = new Date();
dt_date.setDate(1);
if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.nAllowed
range is 01-12.");
dt_date.setMonth(arr_date[1]-1);
if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
dt_date.setFullYear(arr_date[0]);
var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
dt_date.setDate(arr_date[2]);
if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.nAllowed
range is 01-"+dt_numdays.getDate()+".");
return (dt_date)
}
|
|
|
asteinmetz
Newbie
Posts: 1
Registered: 5/21/2003
Member Is Offline
|
| posted on 5/21/2003 at 11:24 AM |
|
|
US dateformat
I'm also using an mysql database that canīt use mm/dd/yyyy but I use the calendar2.js and when I Replace function cal_prs_date1(str_date)
starting at 98 line I get an error!
Do anyone have the replacement code for: calendar2.js
thanks!
|
|
|
nik
Posts:
Registered: 1/1/1970
Member Is Offline
|
| posted on 5/23/2003 at 01:42 PM |
|
|
You should make the following changes in calendar2.js:
// date generating function
function cal_gen_date2 (dt_datetime) {
return (
dt_datetime.getFullYear() + "/"
+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
+ (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()
);
}
// date parsing function
function cal_prs_date2 (str_date) {
var arr_date = str_date.split('/');
if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.nFormat accepted is
dd-mm-yyyy.");
if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.nNo day of month value can be
found.");
if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.nAllowed values are
unsigned integers.");
if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.nNo month value can be found.");
if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.nAllowed values are
unsigned integers.");
if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.nNo year value can be found.");
if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid year value: '" + arr_date[0] + "'.nAllowed values are unsigned
integers.");
var dt_date = new Date();
dt_date.setDate(1);
if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.nAllowed
range is 01-12.");
dt_date.setMonth(arr_date[1]-1);
if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
dt_date.setFullYear(arr_date[0]);
var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
dt_date.setDate(arr_date[2]);
if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.nAllowed
range is 01-"+dt_numdays.getDate()+".");
return (dt_date)
}
And, please, be more attentive while reading forum. This solution has been already mentioned.
|
|
|