The Tamagotchi would normaly be asleep by the time you get to bed. Then you turn off the lights ^_^
Although, a Masktchi and a gozortotchi (sp?) go to bead at 10.00 o'clock. If you do not stay up that late, then you have a problem. You can feed it as much food and play with it/give snacks and then turn the lights off and then when it falls asleep, the lights will already be off.
-or-
If the time is half an hour before it sleeps, you can trun off the light and the tama will automaticly go to sleep ^_^