×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Datetick format

Datetick format

Datetick format

(OP)
Hello,

I am importing some data from excel, on my file the format for the date is dd/mmm/yyyy HH:MM:SS.
Datetick format needs to have it dd-mmm-yyyy HH:MM:SS.

Can someone please help me on how can I convert it to the datetick format please.

thanks
 

RE: Datetick format

Replace "/" with "-".

RE: Datetick format

... using something like strrep().

- Steve

RE: Datetick format

There are two ways to do this.

(1) Easier

Change the date format in excel itself....

format cells-> select custom --> (type the format you need)

your case dd-mmm-yyyy HH:MM:SS

then read this file

(2) Round about way

lets say your excle file first column contians date in any format and second column contains numbers. Save the file in csv format and use textscan command(i believe you cannot read strings using xlsread command)


fid=fopen('FileName.csv','r');
fileformat='%s %f';
data=textscan(fid,fileformat,'headerlines',2,'delimiter',',');
fclose(fid);

Assuming your first and second rows contain some headings/units 'headerlines',2 will ignore first  two rows.

Now 'Data' is a cell data type with Data{1} containing array of date strings

dateformat='dd-mmm-yyyy HH:MM:SS'  % Could be any format

%====if you want to plot use
plot(Data{1},Data{2})
datetick(dateformat)  % Will put your dates in required format on axis


% ==if you want to rewire formatted strings to excel file==

ReqDates=datestr(datenum(Data{1}),dateformat)
ReqDates will contain a string of dates in required format
you can drirectly write/overwrite these dates to you excel file using xlswrite('Filename.xls',ReqDates,'Worksheet','Range');


Hope this helps.

Nodal DOF


 

RE: Datetick format

(OP)
thanks Nodal and sompting
I will try it!

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now