datetime 1429
Batch -change month # to letters
yesterday by 20gnd
First off, you can save yourself all those for statements. Since NT has a built-in DATE var, you can simply use substrings to get the parts you need.
In my case the DATE var is:
Sat 29-04-2006
so doing this:
set YYYYMMDD=%date:~10,4%%date:~7,2%%date:~4,2%
will set a new var called YYYYMMDD
BTW, it's not usually a good idea to alter a built-in var, like DATE.
Moving right along, I guess the simplest way to change 'numeric' month to 'named' month is with a chunk of code like this:
#####
if %MM%==01 set MM=Jan
if %MM%==02 set MM=Feb
if %MM%==03 set MM=Mar
if %MM%==04 set MM=Apr
and so on
#####
My solution:
set __MONTH.01=Jan
set __MONTH.02=Feb
set __MONTH.03=Mar
set __MONTH.04=Apr
set __MONTH.05=May
set __MONTH.06=Jun
set __MONTH.07=Jul
set __MONTH.08=Aug
set __MONTH.09=Sep
set __MONTH.10=Oct
set __MONTH.11=Nov
set __MONTH.12=Dec
REM See also:
REM http://ings.ca/jim/2008/02/10/adding-timestamps-in-a-dos-batch-file/
set cur_yyyy=%date:~10,4%
set cur_mm=%date:~4,2%
for /f "tokens=2* delims=.= " %%a in ('set __MONTH.') do (
if %%a == %cur_mm% set cur_mmm=%%b
)
set monthfolder="%cur_yyyy%-%cur_mm% (%cur_mmm%)"
if not exist %monthfolder% mkdir %monthfolder%
batchfile
batchprogramming
dos
datetime
scripting
tipsandtricks
dammitbrain
sysadmin
batch
programming
reference
solution
In my case the DATE var is:
Sat 29-04-2006
so doing this:
set YYYYMMDD=%date:~10,4%%date:~7,2%%date:~4,2%
will set a new var called YYYYMMDD
BTW, it's not usually a good idea to alter a built-in var, like DATE.
Moving right along, I guess the simplest way to change 'numeric' month to 'named' month is with a chunk of code like this:
#####
if %MM%==01 set MM=Jan
if %MM%==02 set MM=Feb
if %MM%==03 set MM=Mar
if %MM%==04 set MM=Apr
and so on
#####
My solution:
set __MONTH.01=Jan
set __MONTH.02=Feb
set __MONTH.03=Mar
set __MONTH.04=Apr
set __MONTH.05=May
set __MONTH.06=Jun
set __MONTH.07=Jul
set __MONTH.08=Aug
set __MONTH.09=Sep
set __MONTH.10=Oct
set __MONTH.11=Nov
set __MONTH.12=Dec
REM See also:
REM http://ings.ca/jim/2008/02/10/adding-timestamps-in-a-dos-batch-file/
set cur_yyyy=%date:~10,4%
set cur_mm=%date:~4,2%
for /f "tokens=2* delims=.= " %%a in ('set __MONTH.') do (
if %%a == %cur_mm% set cur_mmm=%%b
)
set monthfolder="%cur_yyyy%-%cur_mm% (%cur_mmm%)"
if not exist %monthfolder% mkdir %monthfolder%
yesterday by 20gnd
edatetimebehavior | Extension | Yii Framework
5 days ago by garyburge
Automatically convert ActiveRecord MySQL date and datetime field to PHP5 DateTime Object
convert
to
DateTime
object
extensions
behaviors
date
conversion
CActiveRecord
Yii
from delicious
5 days ago by garyburge
Copy this bookmark: