Question: Is there a differentiable function $f : [0,2] \rightarrow [0,1]$ such that $f(x) = 0$ iff $x=0$ and $f(x) = 1$ iff $x \in [1,2]$? What about $n$ times differentiable for any $n$, or infinitely differentiable? Thank you!

Answer: 
First, let

$$f(x)=\begin{cases}e^{\frac{-1}{x}}&x>0\\0&x\le0\end{cases}$$

It can be shown that $f$ is smooth. Then one such desired function is

$$g(x)=\frac{f(x)}{f(x)+f(1-x)}$$

Since $f$ is smooth, and $f(x)+f(1-x)$ is never $0$, $g$ is also smooth. $g$ takes values $0$ for $x<0$, and values $1$ for $x>1$. It's called a smooth transition function.
How about 

$$f\_n(x) = \left\{
\begin{array}{ll}
 1-(-1)^n(x-1)^n & 0\leq x \leq 1 \\
 1 & 1\leq x\leq 2.
\end{array} \right.
$$

This will be $n-1$-times differentiable for any integer $n\geq 2$.
The graphs of these functions for $n=1$ through $10$ look like so:

![enter image description here](https://i.stack.imgur.com/EjZ1s.png)

As Jared has already shown, we can make the function infinitely differentiable at $x=1$. A minor variation of his example is

$$f(x) = \left\{
\begin{array}{ll}
 1 - e^{1 - 1/(1 - x)} & 0\leq x \leq 1 \\
 1 & 1\leq x\leq 2,
\end{array} \right.
$$

which looks like so:

![enter image description here](https://i.stack.imgur.com/Cj3DZ.png)