I think the first thing that you have to do, would be to check the packaging of the pill. Does it say on the pack when you are meant to take it?
Quite often on the packaging of medication it will tell you what sort of time of day to take it, such as after you have eaten of first thing in the morning. If it advises that you do take the pill before you go to bed, then I would follow this advice.
Sometimes medication will have to be taken a certain number of times a day. If this is the case and you don't want to take the pill before you go to bed any more, then maybe try to take the first pill of the day earlier, so you will not have to take the last one so late.
I also think that you should try and find out if it is definitely the pill that you are taking that is stopping you getting to sleep. Are there any other factors that could be preventing you sleeping? There are many factors that can affect sleeping patterns, such as; drinking caffeine before bed, having something on your mind or taking part in an active activity before trying to get to sleep.
If it is definitely the pill, then maybe it would be worth contacting your doctor and seeing if there is an alternative medication that you could take.
If you are talking about the contraceptive pill, then usually there is no designated time that you have to take it. Just make sure that you take it at the same time every day.
I hope this helps you with your problem.