This article explains how to use your iPhone's clock function to put the phone in sleep mode at a set time in the future.
iPhone sleep mode
Although there is no way to power off your iPhone at a specific future time, you can set your phone to enter “sleep" mode at a certain time. When your iPhone is asleep, it is still powered on, but all applications are closed and the screen goes black. The phone consumes only a minimal amount of battery life in this mode. This function is often used by people who are interested in listening to music while they fall asleep. Since the phone doesn't power off when this function is used, you should take other steps to conserve battery life, including turning off Wi-Fi and 3G and, if you don't need access to the data functions of the phone while you are asleep, turning on airplane mode. All of these functions can be found in the settings menu of your iPhone.
Auto Turn Off iPhone Walkthrough
(1): Locate the clock button on your home screen. Click the square home button on your iPhone to bring you to your phone’s main menu. Included among your application icons on the home screen is a clock icon. Touch this icon.
(2): Enter the timer function. On the bottom of your iPhone’s screen should now be four icons, and the one furthest to the right should read “timer." Touch this icon.
(3): Set the time at which you wish your iPhone to fall asleep. On the top of your screen is now a table with two columns: an “hour" column on the left and a “mins" column on the right. On each column, scroll down to the number of hours or minutes for which you would like your iPhone to remain active. Keep in mind that you are not selecting the time at which you would like your iPhone to go to sleep, but rather the amount of time you would like to elapse before it falls asleep.
(4): Select "sleep iPod." Under the “when timer ends" row, select “sleep iPod." This is the first option on the list.
(5): Hit start. You are now ready to set the timer. Click the green “start button" towards the bottom of the screen. A timer should now appear indicating the amount of time remaining before your phone enters sleep mode. Feel free to exit the clock application and use other features of the phone – the iPhone will still enter sleep mode at the time you indicated.
Hints and Tips
-You can stop the timer and cancel the sleep function at any time by pressing the "cancel" button below the timer.
-The maximum allowable time you can select for the timer is 23 hours and 59 minutes. Be aware that your iPhone will enter sleep mode and your iPod will turn off completely without warning when this time is elapsed, so you want to be sure to pick a time at which you won't mind having your audiobook or podcast suddenly interrupted.
-The other options on the "when timer ends" menu refer to ringtones. You should select one of these rather than the "sleep iPod" option only if you would like your iPhone to sound an alarm rather than fall asleep when the time has elapsed.
Apple iPhone iOS 3.1 User Guide, http://manuals.info.apple.com/en_US/iPhone_iOS3.1_User_Guide.pdf