close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Datepicker and dates

Thread began 12/21/2012 9:16 am by thehalpeen319342 | Last modified 12/21/2012 2:53 pm by Jason Byrnes | 839 views | 7 replies |

thehalpeen319342

Datepicker and dates

Jason, in a recent thread you informed me that if I left a date field blank the browser would return a date 01/01/1970 (European) in the date field.

To work around that, I set the default date in the mysql table to 01/01/1901. However, when someone doesn't submit a date, it doesn't default to 01/01/1901 in the database. How can I get it to do that, or or there any other work around for date fields left blank?

Sign in to reply to this post

Jason ByrnesWebAssist

What data type is the date column?
Date, DateTime, or Timestamp?

A date column requires the format of yyyy-mm-dd. the valid range it will accept is:
'1000-01-01' to '9999-12-31'

for a Date column, to set the default of 01/01/1901, you would need to enter it as:
1901-01-01

DateTime or TimeStamp fields require the date format of:
yyyy-mm-dd hh:ii:ss

for a DateTime field, the supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59', so you would enter the default as:
1901-01-01 00:00:00

A Timestamp, though cannot be set to a date prior to 1970. a timestamp is calculated as the number of seconds that has passed since 1/1/1970. the supported range for a timestamp column is:
'1970-01-01 00:00:01' to '2038-01-19 03:14:07

see the following page for more details
datetime.html

Sign in to reply to this post

thehalpeen319342

Dear Jason, the data type in the date column is date. rthe default date is set to 1901-01-01.

When a user chooses not to enter their birthdate, I would like it to default to to the default date 1901-01-01. Currently if they enter nothing in the date field (Date of birth) (not a required field - they might be to modest/shy) - it produces a 01-01-1970 in the browser page - it's as if an entry is made into mysql and the default date overrided. How do I avoid this?

Sign in to reply to this post

Jason ByrnesWebAssist

are you formatting the date on the browser page that shows it as 01-01-1970?

what if you don't use the formatting? does it show the default date then?

Sign in to reply to this post

thehalpeen319342

Jason below is 3 bits of code on the insert page and after that is the code on the page that displays the date (update page).

INSERT PAGE

// manual insertion re posting date in European format
if(isset($_POST['DOB'])) {
$_POST['DOB'] = date("Y-m-d", strtotime(str_replace("/","-",$_POST['DOB'] )));
}
?>



<script type="text/javascript">
$(function(){
$('#DOB').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
yearRange: "1900:2012",
maxDate: 0,
minDate: new Date(1900, 1 - 1,1),
showAnim: 'show',
onClose: closeDatePicker_DOB
});
});
function closeDatePicker_DOB() {
var tElm = $('#DOB');
if (typeof DOB_Spry != null && typeof DOB_Spry != "undefined" && DOB_Spry.validate) {
DOB_Spry.validate();
}
var docElm = document.getElementById("DOB");
var tBlur = docElm.getAttribute("onBlur");
if (!tBlur) tBlur = docElm.getAttribute("onblur");
if (!tBlur) tBlur = docElm.getAttribute("ONBLUR");
if (tBlur) {
tBlur = String(tBlur).replace(/\bthis\b/g, "docElm");
eval(tBlur);
}
}
</script>


<input id="DOB" name="DOB" type="text" value="<?php echo((isset($_GET["invalid"])?ValidatedField("addmember","DOB"):"")); ?>" class="formTextfield_Medium" tabindex="6" onblur="hideServerError('DOB_ServerError');"/>

_________________________________________________________________________

UPDATE/DETAILS Page - which displays the date

<div class="fieldGroup"> <span id="DOB_Spry"> <span>
<input id="DOB" name="DOB" type="text" value="<?php echo(date("d/m/Y", strtotime($row_rsMembers_Update['memberDOB']))); ?>" class="formTextfield_Medium" tabindex="6" onblur="hideServerError('DOB_ServerError');"/>
<span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldRequiredMsg">Please enter or select a date</span> </span> </span>
<?php
if (ValidatedField('updatemember','updatemember')) {
if ((strpos((",".ValidatedField("updatemember","updatemember").","), "," . "5" . ",") !== false || "5" == "")) {
if (!(false)) {
?>
<span class="serverInvalidState" id="DOB_ServerError">Please enter or select a date</span>
<?php //WAFV_Conditional update_member.php updatemember(5:)
}
}
}?>
</div>
</div>
</div>
</div>
</div>

Sign in to reply to this post

Jason ByrnesWebAssist

try changing this code to:
if(isset($_POST['DOB'])) {
$_POST['DOB'] = date("Y-m-d", strtotime(str_replace("/","-",$_POST['DOB'] )));
}


to:
if(isset($_POST['DOB']) && $_POST['DOB'] != "") {
$_POST['DOB'] = date("Y-m-d", strtotime(str_replace("/","-",$_POST['DOB'] )));
}

Sign in to reply to this post

thehalpeen319342

Jason, I've replaced the code on the insert member page. The mysql database does not default to 01-01-1901 and it displays as 01/01/1970.

Sign in to reply to this post

Jason ByrnesWebAssist

I have created a support ticket so we can look into this issue further.

To view and edit your support ticket, please log into your support history:
supporthistory.php

If anyone else is experiencing this same issue, please append to this thread.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...