PDA

View Full Version : Let users choose their own date and time format


Admin
09-15-2001, 10:00 PM
This hack adds an option for the user to select the date format and time format he wants to use in the forum.
Good for people from different countries, that use different formats.
Requested by markrt.

Demo:
http://www.vbulletin.com/forum/attachment.php?s=&postid=172339

Run this query:
ALTER TABLE user ADD dateformat VARCHAR(4) DEFAULT '-1' not null AFTER timezoneoffset, ADD timeformat VARCHAR(4) DEFAULT '-1' not null AFTER dateformat;
(for more information on running queries visit the Troubleshooting and Problems forum)

In your modifyoptions template add this code:
<tr>
<td bgcolor="{secondaltcolor}"><normalfont><b>Date format</b></normalfont><br>
<smallfont>Select what format you would like to use for dates.</smallfont></td>
<td bgcolor="{secondaltcolor}"><smallfont>
<select name="newdateformat">
<option value="-1" $datedefselected>Use forum default</option>
<option value="0" $date0selected>04-25-1998</option>
<option value="1" $date1selected>04-25-98</option>
<option value="2" $date2selected>04.25.1998</option>
<option value="3" $date3selected>04.25.98</option>
<option value="4" $date4selected>25-04-1998</option>
<option value="5" $date5selected>25-04-98</option>
<option value="6" $date6selected>25.04.1998</option>
<option value="7" $date7selected>25.04.98</option>
<option value="8" $date8selected>April 25th, 1998</option>
<option value="9" $date9selected>Saturday, April 25th, 1998</option>
<option value="10" $date10selected>25th April 1998</option>
<option value="11" $date11selected>Saturday, 25th April 1998</option>
</select></smallfont></td>
</tr>
<tr>
<td bgcolor="{firstaltcolor}"><normalfont><b>Time format</b></normalfont><br>
<smallfont>Select what format you would like to use for times.</smallfont></td>
<td bgcolor="{firstaltcolor}"><smallfont>
<select name="newtimeformat">
<option value="-1" $timedefselected>Use forum default</option>
<option value="0" $time0selected>08:15 pm</option>
<option value="1" $time1selected>08:15:48 pm</option>
<option value="2" $time2selected>08:15 PM</option>
<option value="3" $time3selected>08:15:48 PM</option>
<option value="4" $time4selected>20:15</option>
<option value="5" $time5selected>20:15:48</option>
</select></smallfont></td>
</tr>
right after
<option value="+12" $timezonesel[120]>(GMT +12:00 hours) Auckland, Wellington, Fiji, Kamchatka, Marshall Island</option>
</select></smallfont></td>
</tr>

In member.php add this code:
if ($bbuserinfo[dateformat]!=-1) {
$dateformat="date".$bbuserinfo[dateformat]."selected";
$$dateformat = "selected";
} else {
$datedefselected = "selected";
}

if ($bbuserinfo[timeformat]!=-1) {
$timeformatsel="time".$bbuserinfo[timeformat]."selected";
$$timeformatsel = "selected";
} else {
$timedefselected = "selected";
}
right after
if ($bbuserinfo[timezoneoffset]<0) {
$timezonesel["n".(-$bbuserinfo[timezoneoffset]*10)]="selected";
} else {
$timezonesel[$bbuserinfo[timezoneoffset]*10]="selected";
}
Still in member.php, replace this code:
$DB_site->query("UPDATE user
SET ".$updatestyles."adminemail='$adminemail',
showemail='$showemail',invisible='$invisible',cook ieuser='$cookieuser',
maxposts='".addslashes($umaxposts)."',daysprune='".addslashes($prunedays)."',
timezoneoffset='".addslashes($timezoneoffset)."',emailnotification='$emailnotification',
startofweek='".addslashes($startofweek)."',options='$options',receivepm='$receivepm',
emailonpm='$emailonpm',pmpopup='$pmpopup',usergrou pid='$bbuserinfo[usergroupid]',
nosessionhash='$nosessionhash'
WHERE userid='$bbuserinfo[userid]'");
with this code:
$DB_site->query("UPDATE user
SET ".$updatestyles."adminemail='$adminemail',
showemail='$showemail',invisible='$invisible',cook ieuser='$cookieuser',
maxposts='".addslashes($umaxposts)."',daysprune='".addslashes($prunedays)."',
dateformat='".addslashes($newdateformat)."',timeformat='".addslashes($newtimeformat)."',
timezoneoffset='".addslashes($timezoneoffset)."',emailnotification='$emailnotification',
startofweek='".addslashes($startofweek)."',options='$options',receivepm='$receivepm',
emailonpm='$emailonpm',pmpopup='$pmpopup',usergrou pid='$bbuserinfo[usergroupid]',
nosessionhash='$nosessionhash'
WHERE userid='$bbuserinfo[userid]'");
(note: this code might be changed in your file due to another hack. If so, just add the code that is in red)

In global.php (main directory) add this code:
// change to right date format
if ($bbuserinfo[dateformat]!="-1") {
if ($bbuserinfo[dateformat]=="0") {
$dateformat = "m-d-Y";
} elseif ($bbuserinfo[dateformat]=="1") {
$dateformat = "m-d-y";
} elseif ($bbuserinfo[dateformat]=="2") {
$dateformat = "m.d.Y";
} elseif ($bbuserinfo[dateformat]=="3") {
$dateformat = "m.d.y";
} elseif ($bbuserinfo[dateformat]=="4") {
$dateformat = "d-m-Y";
} elseif ($bbuserinfo[dateformat]=="5") {
$dateformat = "d.m.y";
} elseif ($bbuserinfo[dateformat]=="6") {
$dateformat = "d.m.y";
} elseif ($bbuserinfo[dateformat]=="7") {
$dateformat = "d.m.y";
} elseif ($bbuserinfo[dateformat]=="8") {
$dateformat = "F jS, Y";
} elseif ($bbuserinfo[dateformat]=="9") {
$dateformat = "l, F jS, Y";
} elseif ($bbuserinfo[dateformat]=="10") {
$dateformat = "jS F Y";
} elseif ($bbuserinfo[dateformat]=="11") {
$dateformat = "l, jS F Y";
} else {
$dateformat = "$dateformat";
}
}

// change to right time format
if ($bbuserinfo[timeformat]!="-1") {
if ($bbuserinfo[timeformat]=="0") {
$timeformat = "h:i a";
} elseif ($bbuserinfo[timeformat]=="1") {
$timeformat = "h:i:s a";
} elseif ($bbuserinfo[timeformat]=="2") {
$timeformat = "h:i A";
} elseif ($bbuserinfo[timeformat]=="3") {
$timeformat = "h:i:s A";
} elseif ($bbuserinfo[timeformat]=="4") {
$timeformat = "H:i";
} elseif ($bbuserinfo[timeformat]=="5") {
$timeformat = "H:i:s";
} else {
$timeformat = "$timeformat";
}
}
right after
// ###################### Referrer Stuff #########################

That's it. :D
I know it might look long, but it's really very very easy to install.
If you have any troubles with that block I told you about, ask for help here.

Feedback please! :)

squawell
09-16-2001, 11:53 AM
one question??

Can this hack work in version2.0.3??

where can find this code:

--------------------------------------------------------------------------------ALTER TABLE user ADD dateformat VARCHAR(4) DEFAULT '-1' not null AFTER timezoneoffset, ADD timeformat VARCHAR(4) DEFAULT '-1' not null AFTER dateformat;

Admin
09-16-2001, 12:00 PM
squawell:
This was done on v2.0.3, but should work on all.

What you pasted is not in the files, it's a query you need to run.
Learn more about it here:
http://www.vbulletin.com/forum/showthread.php?s=&threadid=18558

Here's a demo guys. :)

squawell
09-16-2001, 12:13 PM
thanks FireFly~~~

i got it!!

i just see you give the link~~~

is phpmyadmin necessary??

but i do not have it yet!!

should i install ??

Admin
09-16-2001, 12:23 PM
If you have Telnet access, then it's not necessary for this praticular hack.
But it's good to have it, so I suggest you install it.

How did you run the query by the way?

squawell
09-16-2001, 01:30 PM
i look the link find it's need phpmyadmin but i do not have it!!

How did you run the query by the way?-no i don't run the query!!

one question--my forum made in this space[multimania]!!

but i think this space shouldn't support Telnet access,am i ??

have another way to make this hack??

Admin
09-16-2001, 01:34 PM
Nope.

Install phpMyAdmin, it's very easy to install and you'll find it very useful.

Gramphos
09-16-2001, 05:22 PM
Can you allow the user to write in the dateformat itself?

Maybe in normal ways, and not in PHP format (using replace)

MarkB
09-16-2001, 10:34 PM
An excellent enhancement to my board! Thanks!! :D

Freddie Bingham
09-16-2001, 10:42 PM
Squawel and Gramphos please enter your license information in your profile.

[VbbFr]Elie
09-17-2001, 12:22 AM
I just want to add a quite touch to make the script better :)

Use this code to show the moment date and time


In your modifyoptions template add this code:


<tr>
<td bgcolor="#DFDFDF"><normalfont><b>Date format</b></normalfont><br>
<smallfont>Select what format you would like to use for dates.</smallfont></td>
<td bgcolor="#DFDFDF"><smallfont>
<select name="newdateformat">
<option value="-1" $datedefselected>Use forum default</option>
<option value="0" $date0selected>$date1</option> <option value="1" $date1selected>$date2</option>
<option value="2" $date2selected>$date3</option>
<option value="3" $date3selected>$date4</option>
<option value="4" $date4selected>$date5</option>
<option value="5" $date5selected>$date6</option>
<option value="6" $date6selected>$date7</option>
<option value="7" $date7selected>$date8</option>
<option value="8" $date8selected>$date9</option>
<option value="9" $date9selected>$date10</option>
<option value="10" $date10selected>$date11</option>
<option value="11" $date11selected>$date12</option>
</select></smallfont></td>
</tr>
<tr>
<td bgcolor="#F1F1F1"><normalfont><b>Time format</b></normalfont><br>
<smallfont>Select what format you would like to use for times.</smallfont></td>
<td bgcolor="#F1F1F1"><smallfont>
<select name="newtimeformat">
<option value="-1" $timedefselected>Use forum default</option>
<option value="0" $time0selected>$time1</option>
<option value="1" $time1selected>$time2</option>
<option value="2" $time2selected>$time3</option>
<option value="3" $time3selected>$time4</option>
<option value="4" $time4selected>$time5</option>
<option value="5" $time5selected>$time6</option>
</select></smallfont></td>
</tr>


In global.php (main directory) add this code:

// change to right date format


$date1=Date('m-d-Y');
$date2=Date('m-d-y');
$date3=Date('m.d.Y');
$date4=Date('m.d.y');
$date5=Date('d-m-Y');
$date6=Date('d-m-y');
$date7=Date('d.m.Y');
$date8=Date('d.m.y');
$date9=Date('F jS, Y');
$date10=Date('l, F jS, Y');
$date11=Date('jS F Y');
$date12=Date('l, jS F Y');

$time1=Date('h:i a');
$time2=Date('h:i:s a');
$time3=Date('h:i A');
$time4=Date('h:i:s A');
$time5=Date('H:i');
$time6=Date('H:i:s');


if ($bbuserinfo[dateformat]!="-1") {
if ($bbuserinfo[dateformat]=="0") {
$dateformat = "m-d-Y";
} elseif ($bbuserinfo[dateformat]=="1") {
$dateformat = "m-d-y";
} elseif ($bbuserinfo[dateformat]=="2") {
$dateformat = "m.d.Y";
} elseif ($bbuserinfo[dateformat]=="3") {
$dateformat = "m.d.y";
} elseif ($bbuserinfo[dateformat]=="4") {
$dateformat = "d-m-Y";
} elseif ($bbuserinfo[dateformat]=="5") {
$dateformat = "d-m-y";
} elseif ($bbuserinfo[dateformat]=="6") {
$dateformat = "d.m.Y";
} elseif ($bbuserinfo[dateformat]=="7") {
$dateformat = "d.m.y";
} elseif ($bbuserinfo[dateformat]=="8") {
$dateformat = "F jS, Y";
} elseif ($bbuserinfo[dateformat]=="9") {
$dateformat = "l, F jS, Y";
} elseif ($bbuserinfo[dateformat]=="10") {
$dateformat = "jS F Y";
} elseif ($bbuserinfo[dateformat]=="11") {
$dateformat = "l, jS F Y";
} else {
$dateformat = "$dateformat";
}
}

// change to right time format
if ($bbuserinfo[timeformat]!="-1") {
if ($bbuserinfo[timeformat]=="0") {
$timeformat = "h:i a";
} elseif ($bbuserinfo[timeformat]=="1") {
$timeformat = "h:i:s a";
} elseif ($bbuserinfo[timeformat]=="2") {
$timeformat = "h:i A";
} elseif ($bbuserinfo[timeformat]=="3") {
$timeformat = "h:i:s A";
} elseif ($bbuserinfo[timeformat]=="4") {
$timeformat = "H:i";
} elseif ($bbuserinfo[timeformat]=="5") {
$timeformat = "H:i:s";
} else {
$timeformat = "$timeformat";
}
}


I add the french version too

DarkReaper
09-17-2001, 06:12 PM
Hey firefly...think you could get in the habit of putting your hacks in text files? Thanks! :)

Worked great.

Soul Lord XL
09-17-2001, 09:19 PM
Originally posted by [VbbFr]Elie
I just want to add a quite touch to make the script better :)

Use this code to show the moment date and time


In your modifyoptions template add this code:


<tr>
<td bgcolor="#DFDFDF"><normalfont><b>Date format</b></normalfont><br>
<smallfont>Select what format you would like to use for dates.</smallfont></td>
<td bgcolor="#DFDFDF"><smallfont>
<select name="newdateformat">
<option value="-1" $datedefselected>Use forum default</option>
<option value="0" $date0selected>$date1</option> <option value="1" $date1selected>$date2</option>
<option value="2" $date2selected>$date3</option>
<option value="3" $date3selected>$date4</option>
<option value="4" $date4selected>$date5</option>
<option value="5" $date5selected>$date6</option>
<option value="6" $date6selected>$date7</option>
<option value="7" $date7selected>$date8</option>
<option value="8" $date8selected>$date9</option>
<option value="9" $date9selected>$date10</option>
<option value="10" $date10selected>$date11</option>
<option value="11" $date11selected>$date12</option>
</select></smallfont></td>
</tr>
<tr>
<td bgcolor="#F1F1F1"><normalfont><b>Time format</b></normalfont><br>
<smallfont>Select what format you would like to use for times.</smallfont></td>
<td bgcolor="#F1F1F1"><smallfont>
<select name="newtimeformat">
<option value="-1" $timedefselected>Use forum default</option>
<option value="0" $time0selected>$time1</option>
<option value="1" $time1selected>$time2</option>
<option value="2" $time2selected>$time3</option>
<option value="3" $time3selected>$time4</option>
<option value="4" $time4selected>$time5</option>
<option value="5" $time5selected>$time6</option>
</select></smallfont></td>
</tr>


In global.php (main directory) add this code:

// change to right date format


$date1=Date('m-d-Y');
$date2=Date('m-d-y');
$date3=Date('m.d.Y');
$date4=Date('m.d.y');
$date5=Date('d-m-Y');
$date6=Date('d-m-y');
$date7=Date('d.m.Y');
$date8=Date('d.m.y');
$date9=Date('F jS, Y');
$date10=Date('l, F jS, Y');
$date11=Date('jS F Y');
$date12=Date('l, jS F Y');

$time1=Date('h:i a');
$time2=Date('h:i:s a');
$time3=Date('h:i A');
$time4=Date('h:i:s A');
$time5=Date('H:i');
$time6=Date('H:i:s');


if ($bbuserinfo[dateformat]!="-1") {
if ($bbuserinfo[dateformat]=="0") {
$dateformat = "m-d-Y";
} elseif ($bbuserinfo[dateformat]=="1") {
$dateformat = "m-d-y";
} elseif ($bbuserinfo[dateformat]=="2") {
$dateformat = "m.d.Y";
} elseif ($bbuserinfo[dateformat]=="3") {
$dateformat = "m.d.y";
} elseif ($bbuserinfo[dateformat]=="4") {
$dateformat = "d-m-Y";
} elseif ($bbuserinfo[dateformat]=="5") {
$dateformat = "d-m-y";
} elseif ($bbuserinfo[dateformat]=="6") {
$dateformat = "d.m.Y";
} elseif ($bbuserinfo[dateformat]=="7") {
$dateformat = "d.m.y";
} elseif ($bbuserinfo[dateformat]=="8") {
$dateformat = "F jS, Y";
} elseif ($bbuserinfo[dateformat]=="9") {
$dateformat = "l, F jS, Y";
} elseif ($bbuserinfo[dateformat]=="10") {
$dateformat = "jS F Y";
} elseif ($bbuserinfo[dateformat]=="11") {
$dateformat = "l, jS F Y";
} else {
$dateformat = "$dateformat";
}
}

// change to right time format
if ($bbuserinfo[timeformat]!="-1") {
if ($bbuserinfo[timeformat]=="0") {
$timeformat = "h:i a";
} elseif ($bbuserinfo[timeformat]=="1") {
$timeformat = "h:i:s a";
} elseif ($bbuserinfo[timeformat]=="2") {
$timeformat = "h:i A";
} elseif ($bbuserinfo[timeformat]=="3") {
$timeformat = "h:i:s A";
} elseif ($bbuserinfo[timeformat]=="4") {
$timeformat = "H:i";
} elseif ($bbuserinfo[timeformat]=="5") {
$timeformat = "H:i:s";
} else {
$timeformat = "$timeformat";
}
}


I add the french version too

U could tell us whereto put it

Soul Lord XL
09-17-2001, 09:20 PM
I fixed the error, now it is working, but there is 1 problem...

When i click Submit options, it says:

There seems to have been a slight problem with the database. Please try again by pressing the refresh button in your browser.

An E-Mail has been dispatched to our Technical Staff, who you can also contact if the problem persists.

We apologise for any inconvenience.

what is that happening it?

Admin
09-18-2001, 06:34 AM
What's the error you are gettings?
Did you run the query?

Soul Lord XL
09-18-2001, 02:20 PM
The EMAIL says:

Database error in vBulletin: Invalid SQL: UPDATE user
SET styleid='1',adminemail='1',
showemail='1',invisible='0',cookieuser='1',
maxposts='-1',daysprune='-1',
dateformat='9',timeformat='-1',
startofweek='2',options='15',receivepm='1',
emailonpm='0',pmpopup='1',usergroupid='6',
nosessionhash='0'
WHERE userid='1'
mysql error: Unknown column 'dateformat' in 'field list'
mysql error number: 1054
Date: Tuesday 18th of September 2001 01:00:28 AM
Script:
/vbb/member.php?invisible=no&cookieuser=yes&nosessionhash=no&allowmail=yes&showemail=yes&emailnotification=no&receivepm=yes&emailonpm=no&pmpopup=yes&showsignatures=yes&showavatars=yes&showimages=yes&prunedays=-1&umaxposts=-1&startofweek=2&timezoneoffset=-5&newdateformat=9&newtimeformat=-1&vbcode=yes&newstyleset=1&action=updateoptions&Submit=Submit+Modifications
Referer:
http://www.shenlong20xl.com/vbb/member.php?action=editoptions


I cant find that code anywhere

Admin
09-18-2001, 02:36 PM
Looks like you didn't run the query like I said:
ALTER TABLE user ADD dateformat VARCHAR(4) DEFAULT '-1' not null AFTER timezoneoffset, ADD timeformat VARCHAR(4) DEFAULT '-1' not null AFTER dateformat;
Run it using phpMyAdmin or Telnet.

markrt
09-18-2001, 03:01 PM
Hi FireFly

This is to say Thank You for doing this hack.

It works well and has made many of my users very happy.

This would be a very good hack to have included in the next version of VB

Thanks Again.
Mark Thornton

Soul Lord XL
09-18-2001, 05:11 PM
Im not a super expert at hacks or anything firefly.

so can u tell me like what to do more specific (EX: go to folder and then to whatever.php and insert code after bla)

thanx

ubje
09-24-2001, 08:34 PM
Originally posted by FireFly

ALTER TABLE user ADD dateformat VARCHAR(4) DEFAULT '-1' not null AFTER timezoneoffset, ADD timeformat VARCHAR(4) DEFAULT '-1' not null AFTER dateformat;


if you have run this query how can you undo it ????????

Admin
09-25-2001, 12:22 PM
Soul Lord XL:
I can't really be more specific.
Everything is in my first post, add X after/before Y in file Z.php, or add A to the B template.
What exactly don't you understand?

ubje:
ALTER TABLE user DROP dateformat, DROP timeformat

|DarkManX|
11-04-2001, 10:51 PM
awesome hack, works great, installed easily :)

Stretchr
03-04-2002, 06:55 AM
Hello, FireFly.

Thank you for this hack. I'm having one problem, though. When I go into the CP and change the date and time format, they revert to the default. It's also happening with my thread settings. Any idea what could cause this? I cleared the IE cookie cache and that didn't fix it. My users are getting the same thing. Any help will greatly appreciated.

kidney
03-16-2002, 10:46 PM
Hi firefly!

Is there a hack that will force the user to choose a timezone? Most user leave the one that is there by default. I would like to force them to choose their time zone.

Stretchr
03-17-2002, 02:20 PM
I believe you can just add a first field with something like "Choose a Timezone", then require validation and disallow the first choice in the form value. HTH.

Tim Wheatley
03-18-2002, 06:00 AM
Yes if you follow the instructions this does work on 2.2.4 (and on 2.2.2 and 2.2.3 - and probably others).

Tim Wheatley
03-18-2002, 06:17 PM
Is there any way of adding another choice to use 'yesterday' and 'today' too?

Austin Dea
03-18-2002, 08:48 PM
Query doesn't work ;_;

MySQL said:


Duplicate column name 'dateformat'

Admin
03-19-2002, 05:11 AM
Austin Dea - the column is already there, you don't need to run the query again. :)

kidney
03-23-2002, 04:26 AM
Well I did the hack that I requested a couple of post earlier.
You can force people to choose a time when they register.
https://vborg.vbsupport.ru/showthread.php?s=&threadid=36446

Angelus1753
05-07-2002, 09:46 PM
I'm having a nightmare trying to get this hack to install.

I ran the queiry... that went fine (I hope).

I hacked both files correctly (several times once again, to make sure after the first time it failed me).

And added the code to the correct template.

Yet, I get this problem:

http://www.vampire1753.fsnet.co.uk/problem.jpg

I know its not ment to do that, but I don't see anything under the normal time-zone drop-down box (as I assume thats where the date options go).

Yesterday I got the same thing, but a database error message. This has been fixed, as I ran the queiry, but now that problem.

Please help?

Ratchet
08-09-2003, 10:32 PM
Can someone post this hack on one of these subsequent pages. I keep getting a script timeout error when I try and look at page one