Question: How would I clear a date field?

The following code doesn't seem to work:

```
    if (Xrm.Page.getAttribute("new_boolfield1").getValue() != null) {

       switch(Xrm.Page.getAttribute("new_boolfield1").getValue()) {

        case false:

          Xrm.Page.getAttribute("new_datefield1").setValue(null); // this doesn't work
          Xrm.Page.getAttribute("new_datefield1").setValue(); // this doesn't work either

        case true:

          Xrm.Page.getAttribute("new_datefield1").setValue(new Date()); 
        }
     }

```

Answer: 
The right way to clear a field in CRM 2011 is to set its value to `null`

```js
Xrm.Page.getAttribute("new_datefield1").setValue(null);

```

If your field still not cleared, can be for two reasons:

1. you are setting the date somewhere else (as jasonscript
suggested)
2. your `new_boolfield1` is not a boolean field (`two
options` inside CRM) but one optionset

You can easily test these conditions, the first check outside the switch, the second with an `alert` or a `console.log`
null is false so this is much cleaner

```
var xrmPage = Xrm.Page;
var date1   = xrmPage.getAttribute("new_datefield1");
var bValid  = xrmPage.getAttribute("new_boolfield1").getValue();
date1.setValue(bValid ? new Date() : null);

```

Voted up the answer above since it will also correct your code