Removing hours and minutes from date
Show older comments
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
Jan
on 12 Jun 2018
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?
alpedhuez
on 12 Jun 2018
alpedhuez
on 12 Jun 2018
Rik
on 12 Jun 2018
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?
alpedhuez
on 12 Jun 2018
Rik
on 12 Jun 2018
Please show the non-working code in a format we can reproduce.
Regarding your comment: https://www.mathworks.com/matlabcentral/answers/405315-removing-hours-and-minutes-from-date#comment_577922:
one datetime object is scalar, so it makes no sense to index into it. All you need to do is change its Format property.
Jan
on 12 Jun 2018
@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.
Walter Roberson
on 12 Jun 2018
We will also need to know which MATLAB release you are using.
alpedhuez
on 12 Jun 2018
Stephen23
on 13 Jun 2018
OP started a new question here:
Jan
on 13 Jun 2018
@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.
alpedhuez
on 13 Jun 2018
"It would be helpful to have some variable name checkers implemented in a future release"
doc which
doc whos
"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".
alpedhuez
on 13 Jun 2018
Rik
on 13 Jun 2018
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).
alpedhuez
on 13 Jun 2018
@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)
??
Walter Roberson
on 13 Jun 2018
Conflicts between variables hint that you should be breaking your code up into smaller functions.
Answers (0)
Categories
Find more on File Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!