It's a matter of dosage. Lower doses are more likely to act as anxiolytics, while higher doses will act as hypnotics. Diazepam is a fairly weak benzo though, and rarely used as a hypnotic. In a hospital setting, diazepam is usually used to prevent alcohol withdrawals, while temazepam or zolpidem...