1
$\begingroup$

Date[] returns the current date of local system, Date[1] returns {2012, 11, 15, 17, 41, 0.3161629}, Date[2] returns {2012, 11, 15, 18, 41, 0.3161629}, and Date[3] returns {2012, 11, 15, 18, 41, 0.3161629} and so on and why? Also, I tried this code

    a = DateList[] (*line 1*)
    a = a + {0, 0, 0, 1, 0, 0} (*Line 2*)

After executing Line 2 for a few more times I get {2012, 11, 15, 25, 41, 0.3161629}. How can I fix this as I want to use increment time by 1 hour or 30 min in a For loop

$\endgroup$
  • 1
    $\begingroup$ Date[] is deprecated; any reason why you need to use it instead of DateList[]? $\endgroup$ – J. M.'s technical difficulties Nov 15 '12 at 16:49
  • $\begingroup$ From the Date documentation "Date has been superseded by DateList since Version 6.0." and it says first argument is timezone, i.e. how many hours away from GMT. I recommend using DateList $\endgroup$ – ssch Nov 15 '12 at 16:50
  • $\begingroup$ Can i use date as loop counter $\endgroup$ – Soum Nov 15 '12 at 16:55
  • $\begingroup$ And use DatePlus when adding to a date (see DateDifference too) $\endgroup$ – ssch Nov 15 '12 at 17:07
  • $\begingroup$ Yeah i got it. Thanks $\endgroup$ – Soum Nov 15 '12 at 17:12
6
$\begingroup$

Date is deprecated. According to the Mathematica 5 documentation, Date[z] returns the time in time zone z.

You probably want to use DateList to accomplish the kinds of things you are describing. The following will add an hour and a half to the current date:

date = DateList[]
DatePlus[date, 3/48]

(* Out:
  {2012, 11, 15, 12, 7, 3.572165}
  {2012, 11, 15, 13, 37, 3.572}
*)

This works because DatePlus[date, n] adds n days to date and $1.5$ hours is $3/48$ of a day. There's probably a better way to specify the units; you could consult the DatePlus documentation to find out.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.