Skip to main content

Posts

Showing posts with the label date

Working with the Date in Excel

I was just asked by my colleague how to turn 20080101 (in a file provided by a client) to 01/01/2008 (to be used in our system) in Excel where the cell is presented as text. We can easily recognise the date, but computers are not so intelligent to put up with these variations of how we operate. There are a number of ways, but mine relies on certain assumptions, that numbers below 10 are pre-padded with a zero (0), ie. the 9th is represented as 09. This method uses the VB functions in Excel, but for simpilicity's sake I will break this down into stages. For this example, I will use the above date (20080101) which is in cell A1. Firstly, we need to split the date in and use cells A4, B4, and C4: So we need to use a formula in A4 to get the year, B4 to get the month and C4 to get the day: Year =LEFT(A1,4) Month =MID(A1,5,2) Day = RIGHT(A1,2) The LEFT function is to get the first four digits. The MID function is to get the middle 2 digits starting from the 5th position. The RIGH...

Creating a file with current date in a Batch process

With the plethora of sites out there with information on creating Batch processes, it's easy to get overwhelmed and confused over the series of DOS commands. I have a Batch process which restarts a hungry service daily, only to ensure that it cleans up the memory (which it doesn't do so well). The next requirements is for the Batch process to backup the service's log file... with the date. The command that does this for me is: %date:~-4,4%-%date:~-7,2%-%date:~0,2% log.txt This creates the filename in the following format: 2008-06-02 log.txt If you are including this in long path names delimited with quotations ("), it will still work. Just include the command as if it's part of the filename.