The reason why compression socks are worn in the first place determines for exactly how long they should be worn.
For example, if you are wearing relatively light compression socks simply for comfort purposes on an everyday basis, they can be worn as and when required. When standing for long periods for example, sitting in the same position with little to no movement or suffering mild discomfort or leg-fatigue during pregnancy, light compression socks can be used on something of an ad-hoc basis as and when required.
Likewise, compression socks that are used as a preventative treatment against DVT while flying only need to be used during the flight itself. They can be put on shortly before departure and once again removed upon arrival at the final destination. There’s no specific benefit to be had from wearing them for any longer periods than this.
However, if you are required (or recommended) to wear compression garments for medical purposes, your doctor will advise you on exactly how long they should be worn for and at what specific times of day and/or night. In some instances, it may be necessary only to wear them during specific times or while carrying out certain activities. In others, they may need to be worn on a near 24/7 basis.
Likewise, compression socks may be recommended for a couple of weeks, several months or even on a permanent basis. This is something that can only be determined by a medical professional, who will offer tailored advice and support in accordance with your own unique requirements.