473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can I use a php variable on javascript?

106 100+
I know very little about Javascript..

It's for a countdown script.

As far as I can tell, the javascript gets the 'today date and time' somehow (from the user's system).

But I want to modify it so that it gets the server time (using php date).
So I'll need to create a php variable and then add it to the javascript.(?) How do I do this?

here's some of the script:

Expand|Select|Wrap|Line Numbers
  1. function countdown(yr, mo, da, deadlineHr, minute){
  2.  
  3. var montharray = new Array("ene","feb","mar","abr","may","jun","jul","ago","sep","oct","nov","dic");
  4. //deportes should be passing in UTC times, daylight savings not accurate for non-us
  5. var UTCDeadlineHr = deadlineHr;
  6. var UTCMilliseconds = 1000 * 60 * 60 * UTCDeadlineHr;
  7. var today = new Date();
  8. var todayy = today.getUTCFullYear();
  9. if (todayy < 1000)
  10. todayy+=1900;
  11. var todaym = today.getUTCMonth();
  12. var todayd = today.getUTCDate();
  13. var todayh = today.getUTCHours();
  14. var todaymin = today.getUTCMinutes();
  15. var todaysec = today.getUTCSeconds();
  16.  
  17. td= new Date(Date.UTC(todayy, todaym, todayd, todayh, todaymin, todaysec));
  18.  
  19.  
  20. endDate = new Date(Date.UTC(yr, mo-1, da, deadlineHr, minute, 0));
  21.  
  22. var dd = (endDate - td);
  23.  
Sou you can see that td is the current date (today) and that endDate is the target date we are counting down to. The var. dd is the result between the subtraction of endDate by td, which gives us the time left.
Jun 18 '10 #1
4 1654
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var currenttime = '<? echo date("F d, Y H:i:s", time()) ?>';
  3. var serverdate = new Date(currenttime);
  4. </script>
The above code will get the server date time and parse it into javascript date and time.
Jun 20 '10 #2
londres9b
106 100+
Thanks!!

So what do I do, after inserting that code onto the script I do something like this ?

Expand|Select|Wrap|Line Numbers
  1. td= var serverdate;
As I said, I don't know nothing about Javascript..
if you could help with this..
Jun 20 '10 #3
Expand|Select|Wrap|Line Numbers
  1. function countdown(yr, mo, da, deadlineHr, minute){
  2.  
  3. var montharray = new Array("ene","feb","mar","abr","may","jun","jul","ago","sep","oct","nov","dic");
  4. //deportes should be passing in UTC times, daylight savings not accurate for non-us
  5. var UTCDeadlineHr = deadlineHr;
  6. var UTCMilliseconds = 1000 * 60 * 60 * UTCDeadlineHr;
  7. var today = new Date();
  8. var todayy = today.getUTCFullYear();
  9. if (todayy < 1000)
  10. todayy+=1900;
  11. var todaym = today.getUTCMonth();
  12. var todayd = today.getUTCDate();
  13. var todayh = today.getUTCHours();
  14. var todaymin = today.getUTCMinutes();
  15. var todaysec = today.getUTCSeconds();
  16.  
  17. var currenttime = '<? echo date("F d, Y H:i:s", time()) ?>';
  18. var serverdate = new Date(currenttime);
  19.  
  20. td= serverdate; 
  21.  
  22. endDate = new Date(Date.UTC(yr, mo-1, da, deadlineHr, minute, 0));
  23.  
  24. var dd = (endDate - td);

I have updated your code, this might work for you.
Jun 20 '10 #4
londres9b
106 100+
I appreciate your help but no...
It didn't work..

All I got was NaN:NaN:NaN:NaN

If you still want to help me, here is the page source code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <span id="dys"></span>:<span id="hrs"></span>:<span id="min"></span>:<span id="sec"></span>
  4.  
  5. <script type="text/javascript" src="countdownClock.js"></script>
  6. <script language="javascript">
  7.     // yr, mo, day, hr (24 hr format)
  8.     countdown(2010, 7, 19, 21, 9, true)
  9. </script>
  10. </body>
  11. </html>
  12.  
And here is the countdownClock.js , already modified with the code you provided.
countdownClock.txt
Jun 20 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dan Tartakovsky | last post by:
Hi, folks. Does this error below look familiar to you? I'm trying to access function in one frame from the other frame. Error is received while working with Opera or Netscape (different errors)....
1
by: Stefano | last post by:
Posted: Fri Jan 23, 2004 3:59 pm Post subject: Variable Javascript -------------------------------------------------------------------------------- Hi all, i have a problem with...
3
by: Enoch Chan | last post by:
I would like to set a Session variable to a value. In Vbscript it should be Session("ZoomValue")=500 How can I set this session variable by using Javascript? Thanks
5
by: ANTISPAM_garycnew_ANTISPAM | last post by:
I am trying to create/update a Php Session with Javascript to confirm if users have Javascript enabled. My first thought was to create a Javascript that writes a script tag referencing a php...
2
by: Beffmans | last post by:
HI how to pass client side variable(javascript) to an asp.net webform? I was thinking using an invisible asp:textbox control to store the value in? any ideas? thanks Bert
7
by: jagsmiles | last post by:
Hi Friends, I have to perform a lot of editing of xml data on the client-side(browser), using javascript. (before i display the data on the browser). Which xml parser is better for accessing...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
1
by: talhakarkun | last post by:
hi all i have one html page which includes following input control from user: senderEmailId: Subject: body: receiverEmailId: submit button:
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.