Welcome Guest, Not a member yet? Register   Sign In
Get current user's date
#1

[eluser]bondjp[/eluser]
Hi,
I need to check what's the current date where the user is in.
I don't need the time, just the current date.
How can i do it?
Thanks.
#2

[eluser]LuckyFella73[/eluser]
http://www.codeproject.com/KB/scripting/...vreme.aspx
#3

[eluser]Rey Philip Regis[/eluser]
You need to use javascript if you want to check the users current date.... remember that php is server side and javascript is client side. So you will need to use javascript for that....
#4

[eluser]bondjp[/eluser]
I managed to get the users date. Now i have a problem where i can't get strtotime to parse it.
The date is shown correctly

[removed]
Code:
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()+1
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
if (month<10)
month="0"+month

var cdate=month+"/"+daym+"/"+year

if (document.all)
document.all.clock[removed]=cdate
else if (document.getElementById)
document.getElementById("clock")[removed]=cdate
else
[removed](cdate)
}

if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
getthedate()
//if (document.all||document.getElementById)
//setInterval("getthedate()",1000)
}



HTML:


$curdate="<span id=clock></span>";
$newdate = strtotime ( '-0 year' , strtotime ( $curdate ) ) ;
$curdate=date ( 'Y-m-d' , $newdate );
echo form_hidden('curdate','',$curdate);
#5

[eluser]bondjp[/eluser]
Ok. think i know what's going on.
Since php is server side when the page displays, the variable has nothing and therefore strtotime gives 0.
I see that the strtotime displays 0 and then after a 1-2 seconds i get the value displayed from the $curdate variable.

I'm trying to send that value when i submit the form so that i get the current value from the client side but i'm still getting 0 when using strtotime(date shows as 1970-01-01).

Here's the part of the form where i insert the date:

Code:
&lt;?php
$curdate='<span id=clock></span>'; //Print_r shows current date
$newdate = strtotime ( '-0 year'  , strtotime ( $curdate ) ) ; //Failed to parse. Shows 0
$curdate=date ( 'Y-m-d' , $newdate ); //Doesn't work. Shows 1970-01-01
echo form_hidden('curdate',$curdate);
?&gt;
<td>&lt;input type="image" src="&lt;?php echo base_url();?&gt;images/send.png" alt="Submit button" /&gt;&lt;/td>


Shouldn't the updated value of $curdate be passed with the form when i click submit?
#6

[eluser]bondjp[/eluser]
Still trying to get the variable to pass to the controller.
Here's my latest code:


Code:
$(document).ready(function() {
    $('#submit').click(function() {

var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()+1
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
if (month<10)
month="0"+month
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()

var cdate=+month+"/"+daym+"/"+year

$.post('user/available', {curdate: cdate});
        alert(cdate);

        
});
});

Controller:

Code:
$curdate=$this->input->post('curdate');


What i'm doing wrong?
Anyone can help me on this one?
Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB