Removing hours and minutes from date

I have an entry
04/20/2016 00:00
I want to set it just to
04/20/2016
Please advise the steps.

22 Comments

It depends on what "I have an entry" means. Is it written on paper, stored in a variable of the class datetime, saved in a text file or a string?
It is an entry in a table.
The error message is:
Function 'subsindex' is not defined for values of class 'datetime'.
If it is already a datetime object with 00:00, there is nothing left to remove, but it's purely a matter of displaying. So where do you want to display/print it?
Because I got an error message and cannot plot.
Please show the non-working code in a format we can reproduce.
Stephen23
Stephen23 on 12 Jun 2018
Edited: Stephen23 on 13 Jun 2018
one datetime object is scalar, so it makes no sense to index into it. All you need to do is change its Format property.
@alpedhuez: "An entry in a table" can be a variety of things. Please explain this exactly. Prefer to post some code, which creates the data.
Whenever you mention in the forum, that you get an error message, post a copy of it. We cannot read your mind or your screen. The less the readers have to guess, the faster you get a solution.
We will also need to know which MATLAB release you are using.
@alpeduez: Summary:
You have a file with this contents:
X,Y
1/3/09,1.00
1/5/09,0.00
1/7/09,0.00
1/9/09,14.00
1/11/09,106.00
1/13/09,116.00
1/15/09,136.00
1/17/09,109.00
1/19/09,120.00
1/21/09,115.00
  • Which method do you use to import it?
  • Which code do you run currently? Post the relevant part.
  • Post a copy of the complete error message also.
If these information is provided, an answer will need some lines only and is most likely given after a few minutes. You are one of the top-ten askers in this forum, so I expect that you are familiar with the fact, that sharing the details of the problem helps to solve them efficiently.
It was solved - it had some conflicting names in other part of the program. It would be helpful to have some variable name checkers implemented in a future release. Thank you.
"It would be helpful to have some variable name checkers implemented in a future release"
doc which
doc whos
alpedhuez
alpedhuez on 13 Jun 2018
Edited: alpedhuez on 13 Jun 2018
I meant checking when running the code. Thank you.
Stephen23
Stephen23 on 13 Jun 2018
Edited: Stephen23 on 13 Jun 2018
"I meant checking when running the code."
How could MATLAB know the difference between a conflict, and you just using (accessing/redefining) a variable? What is the difference? How do you define "conflict"? Please show an example.
I don't see how it is possible for any code interpreter to know when my usage of a variable is a "conflict", or when I intentionally redefine or use that variable, unless it learns and understands what the code is doing. Any warnings along the lines of "this variable is already defined" would be pop up regularly, irritate the user, and would ultimately end up being ignored. Please explain how your concept would identify such "conflicts".
I just meant that it could make sense to include this type of analysis in "Warnings" section. Do not think it irritates a user when there are significant possibilities that these errors can halt the code. As a bottom line, it is not a big deal.
I regularly overwrite variable like looping variables or temporary container variables. I would not like to have my m-lint full of warnings when I do, that would defeat the usefulness of the m-lint. I like to keep it green (I add the %#ok flag if I don't resolve the source of the warning). That way I can immediately spot new warnings/errors when they pop up.
I would not want to force my workflow on everybody, but I think its not too far from the intended use. I don't see how your suggestion could be implemented so that it helps you solve this issue, without making it very cumbersome to get the green flag from m-lint (without a forest of %#ok).
I just meant that this checking can be implemented as a pre-processing before the code runs. As a bottom line, it is not a big deal.
@alpedhuez: I am asking for an exact definition of what a "conflict" is. Because any code checking tool would need an exact definition of "conflict", which so far you have not given us. Simply saying "... this type of analysis" has no meaning to me, or to any interpreter, which is why I am asking you what your definition is. I am genuinely interested. I wrote about one possibility (redefining variables), but I am interested to know what you mean by a "conflict". Please help me understand what you want to classify as a "conflict":
* changing a variable's value
* changing a variable's class
* accessing a variable (main function)
* accessing a variable (nested function)
* accessing a variable (evalin, etc)
* indexing into a variable
* clearing a variable
* ... ?
And how is the interpreter supposed to know the difference between these:
  • accessing a variable (a conflict)
  • accessing a variable (I just want to access that variable)
??
alpedhuez
alpedhuez on 13 Jun 2018
Edited: alpedhuez on 13 Jun 2018
At this moment I have deadlines so I need to get back to this issue then. Thank you for understandings.
Conflicts between variables hint that you should be breaking your code up into smaller functions.

Sign in to comment.

Answers (0)

Products

Tags

Asked:

on 12 Jun 2018

Commented:

on 13 Jun 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!