long and short format date

how to write long format date ( 31 may 2011) in one screen in next screen the date should appear as 31/5/2011 ..

i am working on reminders/to do list program i am not able to get the dates in required format .

i have declared class called date
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using namespace std;

void remindersList();

class memo
{
public:
    
    string message;
    string date;
    string time;
    
    void displayItems();
    void outputLongFormat();
    void outputShortFormat();
    
}memoObject[4];

string firstReminder;

void memo::displayItems()
{
    
    cout<<"\n"<<memoObject[0].message<<endl;
    cout<<"\n"<<memoObject[0].date<<","<<memoObject[0].time<<endl;
    
    int select;
    
    cout<<"\nPress 1 to view all the reminders"<<endl;
    cin>>select;
    
    switch (select)
    {
        case 1:
            remindersList();
            break;
            
        default:displayItems();
            break;
    }
     
}
void remindersList()
{
    for (int i=0; i<=3; i++)
    {
        cout<<"\n"<<memoObject[i].message<<endl;
    }
}

class date
{
int day;
string month;
int year;

 int day;
    int month;
    int year;
    
    void input();
    void formatSelection();
    void displayLongFormat();
    void displayShortFormat();
    
}dateObject;

void date::input()
{
    cout<<"Enter day"<<endl;
    cin>>day;
    
    cout<<"Enter month"<<endl;
    
    cout<<"\nSelect the month"<<endl;
    
    cout<<"\n1.Jan"<<endl;
    cout<<"2.Feb"<<endl;
    cout<<"3.Mar"<<endl;
    cout<<"4.Apr"<<endl;
    cout<<"5.May"<<endl;
    cout<<"6.June"<<endl;
    cout<<"7.July"<<endl;
    cout<<"8.Aug"<<endl;
    cout<<"9.Sept"<<endl;
    cout<<"10.Oct"<<endl;
    cout<<"11.Nov"<<endl;
    cout<<"12.Dec\n"<<endl;
    
    cin>>month;
    
    switch (month)
    {
        case 1:
            cout<<"Jan"<<endl;
            break;
        case 2:
            cout<<"Feb"<<endl;
            break;
        case 3:
            cout<<"Mar"<<endl;
            break;
        case 4:
            cout<<"Apr"<<endl;
            break;
        case 5:
            cout<<"May"<<endl;
            break;
        case 6:
            cout<<"June"<<endl;
            break;
        case 7:
            cout<<"July"<<endl;
            break;
        case 8:
            cout<<"Aug"<<endl;
            break;
        case 9:
            cout<<"Sept"<<endl;
            break;
        case 10:
            cout<<"Oct"<<endl;
            break;
        case 11:
            cout<<"Nov"<<endl;
            break;
        case 12:
            cout<<"Dec"<<endl;
            break;
            
        default:displayLongFormat();
            break;
    }
    cout<<"Enter Year"<<endl;
    cin>>year;
    
}
void date::displayLongFormat()
{
    for (int i=0; i<=3; i++)
    {
        cout<<" "<<dateObject.day<<" "<<dateObject.month<<dateObject.year<<endl;
    }
}


void date::displayShortFormat()
{
    int monthShortFormat;

    switch (monthShortFormat)
    {
        case 1:
            cout<<"1"<<endl;
            break;
        case 2:cout<<"2"<<endl;
            break;
        default:
            break;
    }
}
int main (int argc, const char * argv[])
{

    memoObject[0].message="Go and get milk";
    memoObject[0].date="28 May 2011";
    memoObject[0].time="1:40";
    
    memoObject[1].message="Drink Tea";
    memoObject[1].date="28 May 2011";
    memoObject[1].time="2:00";
    
    memoObject[2].message="Sleep";
    memoObject[2].date="28 May 2011";
    memoObject[2].time="3:00";
    
    memoObject[3].message="Watch IPL";
    memoObject[3].date="28 May 2011";
    memoObject[3].time="6:00";

  
    memoObject[0].displayItems();


Last edited on
i am working on reminders/to do list program i am not able to get the dates in required format.
You don't seem to have the data structures necessary to support a to do list with reminders. Once you sort out your data structures, you'll discover you need a data/time class to do all the conversions.

We can help you along the way, but you're not headed in the right direction.
hmm sorry didnt get you .
Look at this http://www.cplusplus.com/reference/clibrary/ctime/ctime/

There're a lot of function to deal with date/time. Like strftime http://www.cplusplus.com/reference/clibrary/ctime/strftime/ which is similar to printf just for formating date/time.

struct tm http://www.cplusplus.com/reference/clibrary/ctime/tm/ already contains the members (and more) of your class date. Better use that struct and don't forget to set the unused members to 0.
can i write this program without using strftime / ctime in C++ ?
Topic archived. No new replies allowed.