SRL Archive - SRL Archives

TheDate returns the date like this: December 31, 2006


Ron

2006-12-31 17:40:03

TheDate returns the date like this: December 31, 2006


// TheDate will return the current date in this format: Month Day, Year
// Made by Ron :)
function TheDate : String;
var
Year, Month, Day : Word;
M, D : String;
begin
DecodeDate(Date, Year, Month, Day);
case Month of
1 : M := 'January';
2 : M := 'February';
3 : M := 'March';
4 : M := 'April';
5 : M := 'May';
6 : M := 'June';
7 : M := 'July';
8 : M := 'August';
9 : M := 'September';
10 : M := 'October';
11 : M := 'November';
12 : M := 'December';
end;
case Day of
1 : D := 'st';
2 : D := 'nd';
3 : D := 'rd';
end;
if(Day > 3)then
D := 'th';
Result := M+' '+IntToStr(Day)+D+', '+IntToStr(Year);
end;

Test function code:

program New;

// TheDate will return the current date in this format: Month Day, Year
// Made by Ron :)
function TheDate : String;
var
Year, Month, Day : Word;
M, D : String;
begin
DecodeDate(Date, Year, Month, Day);
case Month of
1 : M := 'January';
2 : M := 'February';
3 : M := 'March';
4 : M := 'April';
5 : M := 'May';
6 : M := 'June';
7 : M := 'July';
8 : M := 'August';
9 : M := 'September';
10 : M := 'October';
11 : M := 'November';
12 : M := 'December';
end;
case Day of
1 : D := 'st';
2 : D := 'nd';
3 : D := 'rd';
end;
if(Day > 3)then
D := 'th';
Result := M+' '+IntToStr(Day)+D+', '+IntToStr(Year);
end;

begin
ClearDebug;
WriteLn(TheDate);
end.

~Ron

bullzeye95

2007-01-14 16:19:40

Nice job Ron. I didn't know about DecodeDate or DecodeTime before this. I hope you don't mind, (which, knowing you, you won't :P) but I built a LOT on this.
function GetDate(getTime, displayWords, militaryTime: Boolean): String;
var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
M, D: String;
begin
if(displayWords)then
begin
DecodeDate(Date, Year, Month, Day);
case Month of
1 : M := 'January';
2 : M := 'February';
3 : M := 'March';
4 : M := 'April';
5 : M := 'May';
6 : M := 'June';
7 : M := 'July';
8 : M := 'August';
9 : M := 'September';
10 : M := 'October';
11 : M := 'November';
12 : M := 'December';
end;
case Day of
1 : D := 'st';
2 : D := 'nd';
3 : D := 'rd';
end;
if(Day > 3)then
D := 'th';
if(getTime)then
begin
DecodeTime(time, Hour, Min, Sec, MSec);
if(not(militaryTime))then
begin
if(Hour > 12)then
begin
Hour:= Hour-12;
Result:= M+' '+IntToStr(Day)+D+', '+IntToStr(Year) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
Result:= M+' '+IntToStr(Day)+D+', '+IntToStr(Year) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
end
else
Result := M+' '+IntToStr(Day)+D+', '+IntToStr(Year);
end;
if(not(displayWords))then
begin
if(getTime)then
begin
DecodeTime(time, Hour, Min, Sec, MSec);
if(not(militaryTime))then
begin
if(Hour > 12)then
begin
Hour:= Hour-12;
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
if(not(Hour > 12))then
begin
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
if(militaryTime)then
begin
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
if(not(getTime))then
begin
Result:= DateToStr(date);
end;
end;
end;

I added an option to add the time, an option to display the date with numbers, and an option to do military time, or regular time.

Oh and this also taught me that a Word was a type of integer. Thanks :)

Ron

2007-01-20 23:33:57

Cool add man. :)

Make sure to stick to standards though.

Don't do this.

if (blah) then
begin
blah;
end;

Do this:

if (blah) then
begin
blah;
end;

It's just easier to read, debug, etc. ;)

Ejjman

2007-01-23 20:54:21

Standardized…

function GetDate(getTime, displayWords, militaryTime: Boolean): String;
var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
M, D: String;
begin
if(displayWords)then
begin
DecodeDate(Date, Year, Month, Day);
case Month of
1 : M := 'January';
2 : M := 'February';
3 : M := 'March';
4 : M := 'April';
5 : M := 'May';
6 : M := 'June';
7 : M := 'July';
8 : M := 'August';
9 : M := 'September';
10 : M := 'October';
11 : M := 'November';
12 : M := 'December';
end;
case Day of
1 : D := 'st';
2 : D := 'nd';
3 : D := 'rd';
end;
if(Day > 3)then
D := 'th';
if(getTime)then
begin
DecodeTime(time, Hour, Min, Sec, MSec);
if(not(militaryTime))then
begin
if(Hour > 12)then
begin
Hour:= Hour-12;
Result:= M+' '+IntToStr(Day)+D+', '+IntToStr(Year) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
Result:= M+' '+IntToStr(Day)+D+', '+IntToStr(Year) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
end
else
Result := M+' '+IntToStr(Day)+D+', '+IntToStr(Year);
end;
if(not(displayWords))then
begin
if(getTime)then
begin
DecodeTime(time, Hour, Min, Sec, MSec);
if(not(militaryTime))then
begin
if(Hour > 12)then
begin
Hour:= Hour-12;
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
if(not(Hour > 12))then
begin
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
if(militaryTime)then
begin
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
if(not(getTime))then
begin
Result:= DateToStr(date);
end;
end;
end;

Great job, Ron. This would be awesome to use on scripts. Can you say 'Rep++' ? ;)

Wizzup?

2007-01-24 02:57:20

From: ejjman1
Standardized…

function GetDate(getTime, displayWords, militaryTime: Boolean): String;
var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
M, D: String;
begin
if(displayWords)then
begin
DecodeDate(Date, Year, Month, Day);
case Month of
1 : M := 'January';
2 : M := 'February';
3 : M := 'March';
4 : M := 'April';
5 : M := 'May';
6 : M := 'June';
7 : M := 'July';
8 : M := 'August';
9 : M := 'September';
10 : M := 'October';
11 : M := 'November';
12 : M := 'December';
end;
case Day of
1 : D := 'st';
2 : D := 'nd';
3 : D := 'rd';
end;
if(Day > 3)then
D := 'th';
if(getTime)then
begin
DecodeTime(time, Hour, Min, Sec, MSec);
if(not(militaryTime))then
begin
if(Hour > 12)then
begin
Hour:= Hour-12;
Result:= M+' '+IntToStr(Day)+D+', '+IntToStr(Year) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
Result:= M+' '+IntToStr(Day)+D+', '+IntToStr(Year) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
end
else
Result := M+' '+IntToStr(Day)+D+', '+IntToStr(Year);
end;
if(not(displayWords))then
begin
if(getTime)then
begin
DecodeTime(time, Hour, Min, Sec, MSec);
if(not(militaryTime))then
begin
if(Hour > 12)then
begin
Hour:= Hour-12;
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
if(not(Hour > 12))then
begin
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
if(militaryTime)then
begin
Result:= DateToStr(date) + ' ' + IntToStr(Hour)+':'+IntToStr(Min)+':'+IntToStr(Sec);
exit;
end;
end;
if(not(getTime))then
begin
Result:= DateToStr(date);
end;
end;
end;

Great job, Ron. This would be awesome to use on scripts. Can you say 'Rep++' ? ;)



Shouldn't you do:


case a of
..
End;

I thoguht you would need to indent that aswell?

Ron

2007-01-24 14:19:18

That's what I thought.

Boreas

2007-01-24 14:37:32

What are the standards for when each number in a case has a begin end? They always look weird.

Starblaster100

2007-01-24 16:13:05

[php]
Case This of
1: Begin
DoThis;
DoThat;
end;
2: Begin
DoThis;
DoThis2;
end;
end;
[/php]

EDIT: Copy into SCAR, it looks a little strange right now…
EDIT2: Ok, PHP code saved it :) No need to copy into SCAR

Boreas

2007-01-24 16:20:02

Ah ok thanks. It looks just as strange in SCAR