Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.8K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

String to Dates?

Posted 10 years ago
POSTED BY: Shaun C
4 Replies
Posted 10 years ago

Thank you again.

POSTED BY: Shaun C
test = {"6/1/1990", "6/4/1990", "6/5/1990", "6/6/1990"} ;
result = Map[
    DateList[{#,{"Day","Month","YearShort"}}]&,
    test
]
result[[;;,1;;3]]
POSTED BY: Ivan Morozov
Posted 10 years ago
POSTED BY: Shaun C

Hi, DateList function expects it's argument to be a string. It looks like you are trying to pass a list of strings to it instead. To convert a list of strings you need to map over it (since DateList is not listable by default, probably because it has a list as second argument):

test = {"6/1/1990", "6/4/1990", "6/5/1990", "6/6/1990"} ;
Map[
    DateList[{#,{"Day","Month","YearShort"}}]&,
    test
]

You can always check whether a function is listable, i.e. f[{x1,x2,..}] = {f[x1],f[x2],...}, or not:

Attributes[Sin]
Attributes[DateList]
POSTED BY: Ivan Morozov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard