Forum Moderators: open

Message Too Old, No Replies

Changing date format

help with script

         

eaglepi

2:24 am on Jul 20, 2003 (gmt 0)

10+ Year Member



I will admit I know very little about scripts so please be very detailed in your answers. Here is my question,

I have a script that I purchased from a company in Russia and their date format is (year,month,day) this is what it looks like now:

Last updated on 2003-07-19
Copyright © 2001-2003

I want to change the script so that the date is displayed (month,day,year)

I want it to look like this:
Last updated on 07-19-2003 or July 19, 2003
Copyright © 2001-2003

I have been told I need to change something in img/lib.js - bottom of GetCurDate()
function

Can someone please tell me exactly what has to be changed, here is that part of the script:

function GetCurDate() {

var today = new Date();
var date = today.getDate();
var day = today.getDay();
var month = today.getMonth();
var year = today.getYear();
var dayName;
var daySuffix;
var monthName;

if (day == 0) dayName = "Sunday";
else if (day == 1) dayName = "Monday";
else if (day == 2) dayName = "Tuesday";
else if (day == 3) dayName = "Wednesday";
else if (day == 4) dayName = "Thursday";
else if (day == 5) dayName = "Friday";
else if (day == 6) dayName = "Saturday";

if (month == 0) monthName = "January";
else if (month == 1) monthName = "February";
else if (month == 2) monthName = "March";
else if (month == 3) monthName = "April";
else if (month == 4) monthName = "May";
else if (month == 5) monthName = "June";
else if (month == 6) monthName = "July";
else if (month == 7) monthName = "August";
else if (month == 8) monthName = "September";
else if (month == 9) monthName = "October";
else if (month == 10) monthName = "November";
else if (month == 11) monthName = "December";

return (dayName + " " + monthName + " " + date + ", " + year);

}


gph

4:06 am on Jul 20, 2003 (gmt 0)

10+ Year Member



I hope you didn't pay lots of money for it or you needed it to only work in IE. Otherwise the author needs to do a bit of homework.

To return a 4 digit year xbrowser you need this:

dateObj.getFullYear()

Anyway, this function looks like a good learning tool so I've picked it apart a bit for you.

This part at the bottom of the function makes and returns the date string when GetCurDate() is called

return (dayName + " " + monthName + " " + date + ", " + year);

The brackets around this statement are unneccecary. It can look like this:

return dayName + " " + monthName + " " + date + ", " + year;

spelt out it's saying return the following:

"dayName plus a space plus monthName plus a space plus date plus a comma followed by a space plus year"

To modify it to this:

07-19-2003

you don't need dayName or monthName and the spaces need to be changed to dashes. There's lots of ways to do this but I'll modify your function to help you understand it.

function GetCurDate() {

var today = new Date();
var date = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
var monthNumber;

if (month == 0) monthNumber = "01";
else if (month == 1) monthNumber = "02";
else if (month == 2) monthNumber = "03";
else if (month == 3) monthNumber = "04";
else if (month == 4) monthNumber = "05";
else if (month == 5) monthNumber = "06";
else if (month == 6) monthNumber = "07";
else if (month == 7) monthNumber = "08";
else if (month == 8) monthNumber = "09";
else if (month == 9) monthNumber = "10";
else if (month == 10) monthNumber = "11";
else if (month == 11) monthNumber = "12";

return monthNumber + "-" + date + "-" + year;
}

To see how things work you can put in an alert after a statement. try this:

var month = today.getMonth();
alert(month);

eaglepi

5:01 am on Jul 20, 2003 (gmt 0)

10+ Year Member



Trust me everuday I think more and more that I got screwed, the company who sold me the scripts (which cost $700 for 2 licenses) continues to provide poor support. He answers my support requests on a timely manner but he does not answer the question. I have explained time and time again that I paid the money because I don't know how to write scripts but his "support" for my question I asked you was
"To change date format alter img/lib.js - bottom of GetCurDate()
function
"

Which is what needs to be done but he doesn't tell me what to alter .....lol

anyways enough ****ing.... I tired to copy and paste what you said into the doc but it didn't change anything. Could you please post the part of the script again exactly how it should be so I can copy and paste it into the doc.. I appreciate you trying to explain it to me but I just don't understand scripts at all... Thanks for any and all help

g1smd

7:35 am on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why change the date format? The 2003-07-20 format is simply the International Standard, as it is always Year-Month-Day. This was introduced in the early 1970s and is now valid in 99% of the world.

Changing to a format like 01-12-2003 introduces an ambiguity. Europeans read it as 1st December, whilst in the US and parts of Canada they interpret it as January 12th.

See also RFC 3339 - Date and Time on the Internet, by Chris Newman and Graham Klein and [webmasterworld.com...] .

ShawnR

7:58 am on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

That function is not being used to write the 'last update' text of the page. To find out what part of the code is the part that needs to be changed, search for "Last updated".

Just out of interest, what does the application do? (I'm sure that for $700 you did not just buy a script to modify your 'last updated' date ;)

Shawn

gph

2:16 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



The thread that g1smd posted is a very good read. I'd suggest reading it before making changes.

As Shawn pointed out it looks like we’re changing the wrong function.

I'll be unable to answer you for atleast the next 12 - 16 hours. Read that thread and if you still want things changed post the relevant function(s). In the mean time, if anyone wants to jump in feel free to do so.

eaglepi

4:18 pm on Jul 20, 2003 (gmt 0)

10+ Year Member



Thank you for all the info it was good reading and good info to know... In my case I still want the date as 7-20-2003, my site is only catering to one city in the US, otherwise I would use the standard format. I did fix my script, thank you for all of your input

g1smd

5:25 pm on Jul 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Open the eyes of those city dwellers to the big wide world out there!