date to string conversion

조회 수: 2 (최근 30일)
Lakshmi Chodavarapu
Lakshmi Chodavarapu 2021년 12월 27일
댓글: Lakshmi Chodavarapu 2021년 12월 28일
when using the following code s value is prited as '00000'
Help me what the problem is.. dtntm field has date and time
aa=(DD_SlantSmoothTEC(j).dtntm);
aaa=datestr(aa);
s=strcat(aaa(1:2),aaa(4:6));
fn1=sprintf('%s%s','DD-VTEC Vs UT,HYDE-IISC PRN PAIR DAY ',s);
title(fn1);
  댓글 수: 1
Stephen23
Stephen23 2021년 12월 27일
Do NOT use the outdated, deprecated, imprecise DATESTR, DATEVEC, or DATENUM.
The DATESTR documentation states: "While datestr returns text representing dates and times, it is recommended that you use datetime values to represent points in time, and then convert them to text using the char, cellstr, or string functions."

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2021년 12월 27일
편집: Stephen23 2021년 12월 27일
Ugh, do NOT use DATESTR. This is easier without using the old, imprecise, deprecated functions:
aa = datetime('now','Format','ddMMM');
fn1 = sprintf('%s%s','DD-VTEC Vs UT,HYDE-IISC PRN PAIR DAY ',aa)
fn1 = 'DD-VTEC Vs UT,HYDE-IISC PRN PAIR DAY 27Dec'
  댓글 수: 1
Adam Danz
Adam Danz 2021년 12월 27일
+1 yeah, don't use datestr....

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam Danz
Adam Danz 2021년 12월 27일
편집: Adam Danz 2021년 12월 27일
Assuming you want the date formatted as ddmmm ( see additional format options ),
aa = datetime('now') % or aa = now() for double representation
aa = datetime
27-Dec-2021 17:45:06
s = datestr(aa,'ddmmm')
s = '27Dec'
fn1 = sprintf('%s%s','DD-VTEC Vs UT,HYDE-IISC PRN PAIR DAY ',s)
fn1 = 'DD-VTEC Vs UT,HYDE-IISC PRN PAIR DAY 27Dec'
  댓글 수: 2
Lakshmi Chodavarapu
Lakshmi Chodavarapu 2021년 12월 28일
Many thanks to you all for helping and making me learn.
Lakshmi Chodavarapu
Lakshmi Chodavarapu 2021년 12월 28일
Able to succesfully save the files as requirded. Thanks agan for giving me a precious opportunity to learn.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by