/    Sign up×
Community /Pin to ProfileBookmark

HELP! Converting dates from UTC Format to GMT

I’m just a beginner in Javascript.

I have created an asp page (Week.asp), where there is a form (frmDayAdd). On this form the user can enter a date by clicking on a button and a new window pops up with a calendar. When they click on required date, the calendar window is closed and the date passed to the form field (txtDate) in format dd/mm/yyyy. When the user then clicks the drop down select box (cboTarget) it triggers the javascript function (getDays). This then finds the corresponding day (e.g. Monday) to the date selected (txtDate) and writes it to the table cell (id=’spnDay’).

This all appears to work ok (i.e. a day is shown when above process is carried out) however, the days passed are not the correct days for the date. I think the code is getting confused somewhere with GMT & UTC time formats.

I want it all to work with GMT.

Ive tried various things but with no success, as I said before Ive only just started working with JavaScript.

I would be very grateful if anyone could tell me how to adapt my code

I hope this all makes sense.

My Code is below.

[code=html]…………………………………………………………………………………………………
function getDays(aText)
{
myDays=[“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”,”Sunday”];
myDate=new Date(eval(‘”‘+aText.value+'”‘));
spnDay.innerHTML=myDays[myDate.getDay()]
}

<table align=”center” width=”60%” border=”0″ cellspacing=”1″ cellpadding=”5″>
<form action=”Week.asp?WeekID=<%=strWeekID%>&Day=Add&Mode=Edit” name=”frmDayAdd” Method=”Post”>
<tr>
<td>&nbsp;</td>
<td><input type=”text” name=”txtDate_vis” Value=”<%=strDate%>” size=”15″ style=”font-family: Verdana; font-size: 10pt”>
<input type=”button” value=”…” onClick=”OpenDateWin(‘Y’,’txtDate’,’frmDayAdd’)”>
<input type=”hidden” name=”txtDate” Value=”<%=strDate%>”></td>
<td class=”content” id=’spnDay’></td>
<td><select name=”cboTarget” onFocus=”getDays(frmDayAdd.txtDate_vis)” style=”font-family: Verdana; font-size: 10pt”>
<option value=””>Select</option></td>
</tr>
</table>
…………………………………………………………………………………………………[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 21.2005 — [code=php]function getDays(aText){
myDays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];

myDate=new Date(eval('"'+aText.value.split("/")[1]+"/"+aText.value.split("/")[0]+"/"+aText.value.split("/")[2]+'"'));
// convert to date using MM/DD/YYYY format.

spnDay.innerHTML=myDays[myDate.getDay()]
}[/code]
Copy linkTweet thisAlerts:
@bonus_authorApr 21.2005 — cheers,

that works a treat.

Much appreciated, thanks for taking the time.
Copy linkTweet thisAlerts:
@scragarApr 21.2005 — cheers, [/quote]Your Welcome.that works a treat.[/quote]Glad to know it.Much appreciated, thanks for taking the time.[/quote]It actualy took somewhere around 3 seconds to actualy realise what you meant by UCT, but by then I'd already begun writing. I think it took me less than 10 secs for writing

and sending.
×

Success!

Help @bonus_ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...