Is there any way on how to convert mm/dd/yyyy (my computer date) into yyyydd (julian day) in batch process?
Asked
Active
Viewed 447 times
1 Answers
1
@ECHO OFF
SETLOCAL
FOR %%y IN (2000 2001 2012 2013 2014 2015 2016) DO (
FOR %%d IN (
01/01/%%y 02/01/%%y 02/28/%%y 02/29/%%y 03/01/%%y 04/01/%%y 05/01/%%y
06/01/%%y 07/01/%%y 08/01/%%y 09/01/%%y 10/01/%%y 11/01/%%y 12/01/%%y 12/31/%%y
) DO CALL :julian %%d
)
GOTO :EOF
:julian
SET jdate=%1
SET /a yyyy=%jdate:~-4%&SET /a mm=1%jdate:~0,2%&SET jdate=%jdate:~-4%0%jdate:~3,2%
SET /a yyyy=yyyy %% 4
IF %yyyy% equ 0 IF %mm% gtr 102 SET /a jdate +=1
FOR %%a IN (02:31 03:28 04:31 05:30 06:31 07:30 08:31 09:31 10:30 11:31 12:30) DO (
FOR /f "tokens=1,2delims=:" %%b IN ("%%a") DO IF "1%%b" leq "%mm%" SET /a jdate+=%%c
)
ECHO %1 becomes %jdate%
GOTO :eof
The first part of this routine is simply generating dates including significant dates for selected years.
The :julian
routine actually does the conversion, having been passed the mm/dd/yyyy date from the main routine.
Works for me!

Magoo
- 77,302
- 8
- 62
- 84
-
Do I really need to specify the years and days? How about setting it automatic? wherein this year is leap year, this year is regular year(e.g. 2000,2004,2008 etc. is for leap years while 2001-2003, 2005-2007 and 2009-2011 etc.) same as with days. – lovelyvm Nov 21 '14 at 05:40
-
The for...%%y...%%d... loop is merely providing a set of dates to the `:julian` routine to prove that routine works. All you would need to do in your program would be `call :julian %whatever%` where `whatever` contained your date in mm/dd/yyyy format, and the `jdate` would be returned containing the converted value. – Magoo Nov 21 '14 at 05:53