Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Mathematica 5 date insert' topicStudent Support Forum > General > Archives > "Mathematica 5 date insert"

Help | Reply To Topic
Author Comment/Response
Nik Vassiljev
05/30/09 03:44am

I have a bit of an issue with inserting date into my code. I am only a beginner with Mathematica or any programming for that matter so any help will be appreciated.

I want to insert a date into my code with 2 conditions: 1 - must be easily readable; 2 - must be saved in a variable not just shown. So far I managed to make it but in an unnecessarily complicated way. If anyone could show me a better way of doing it I would appreciate it.

In[69]:=
dt=Date[]

Out[69]=
{2009,5,30,10,42,19.9687500}

In[70]:=
year=ToString[dt[[1]]]
month=If[Length[IntegerDigits[dt[[2]]]]==
1,"0"<>ToString[dt[[2]]],ToString[dt[[2]]]]
day=If[Length[IntegerDigits[dt[[3]]]]==1,"0"<>ToString[dt[[3]]],ToString[dt[[\
3]]]]
hour=If[Length[IntegerDigits[dt[[4]]]]==
1,"0"<>ToString[dt[[4]]],ToString[dt[[4]]]]
minute=If[Length[IntegerDigits[dt[[5]]]]==1,"0"<>ToString[dt[[5]]],ToString[\
dt[[5]]]]
second=If[Length[IntegerDigits[IntegerPart[dt[[6]]]]]\[Equal]1,"0"<>ToString[\
IntegerPart[dt[[6]]]],ToString[IntegerPart[dt[[6]]]]]

Out[70]=
2009

Out[71]=
05

Out[72]=
30

Out[73]=
10

Out[74]=
42

Out[75]=
19

In[76]:=
date2=year<>"_"<>month<>"_"<>day<>" "<>hour<>":"<>minute<>":"<>second

Out[76]=
2009_05_30 10:42:19

Attachment: date_insert.nb, URL: ,
Help | Reply To Topic