Clear Filters
Clear Filters

how to find the first date of each month between years?

2 views (last 30 days)
how to find the first date of each month between years for eg lets take 2000-2008. how to find first date of each month for the years from 2000 to 2008?

Accepted Answer

Cris LaPierre
Cris LaPierre on 27 Oct 2021
dates = datetime(2000,1,1):calmonths(1):datetime(2008,12,1)
dates = 1×108 datetime array
01-Jan-2000 01-Feb-2000 01-Mar-2000 01-Apr-2000 01-May-2000 01-Jun-2000 01-Jul-2000 01-Aug-2000 01-Sep-2000 01-Oct-2000 01-Nov-2000 01-Dec-2000 01-Jan-2001 01-Feb-2001 01-Mar-2001 01-Apr-2001 01-May-2001 01-Jun-2001 01-Jul-2001 01-Aug-2001 01-Sep-2001 01-Oct-2001 01-Nov-2001 01-Dec-2001 01-Jan-2002 01-Feb-2002 01-Mar-2002 01-Apr-2002 01-May-2002 01-Jun-2002 01-Jul-2002 01-Aug-2002 01-Sep-2002 01-Oct-2002 01-Nov-2002 01-Dec-2002 01-Jan-2003 01-Feb-2003 01-Mar-2003 01-Apr-2003 01-May-2003 01-Jun-2003 01-Jul-2003 01-Aug-2003 01-Sep-2003 01-Oct-2003 01-Nov-2003 01-Dec-2003 01-Jan-2004 01-Feb-2004 01-Mar-2004 01-Apr-2004 01-May-2004 01-Jun-2004 01-Jul-2004 01-Aug-2004 01-Sep-2004 01-Oct-2004 01-Nov-2004 01-Dec-2004 01-Jan-2005 01-Feb-2005 01-Mar-2005 01-Apr-2005 01-May-2005 01-Jun-2005 01-Jul-2005 01-Aug-2005 01-Sep-2005 01-Oct-2005 01-Nov-2005 01-Dec-2005 01-Jan-2006 01-Feb-2006 01-Mar-2006 01-Apr-2006 01-May-2006 01-Jun-2006 01-Jul-2006 01-Aug-2006 01-Sep-2006 01-Oct-2006 01-Nov-2006 01-Dec-2006 01-Jan-2007 01-Feb-2007 01-Mar-2007 01-Apr-2007 01-May-2007 01-Jun-2007 01-Jul-2007 01-Aug-2007 01-Sep-2007 01-Oct-2007 01-Nov-2007 01-Dec-2007 01-Jan-2008 01-Feb-2008 01-Mar-2008 01-Apr-2008 01-May-2008 01-Jun-2008 01-Jul-2008 01-Aug-2008 01-Sep-2008 01-Oct-2008 01-Nov-2008 01-Dec-2008

More Answers (1)

Can Atalay
Can Atalay on 27 Oct 2021
years = transpose(2000:2008);
months = transpose(1:12);
[row1,col1] = size(years);
[row2,col2] = size(months);
year_month = zeros(row1*row2,3);
for ii1 = 1:row1
year_month((ii1-1)*row2+1:ii1*row2,:) = [repmat(years(ii1),[row2 1]) months repmat([1],[row2 1])];
datetime(year_month) % your answer


Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!