Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Date and Time

Locked
ruiascensao
Posts: 177
Joined: Tue Nov 15, 2011 2:24 pm

Date and Time

Unread post by ruiascensao »

Hi,

How can I have a text object with data + time?

Thank You,

Best Regards,
Rui
BR
Rui
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Date and Time

Unread post by admin »

Rui,

You can just use a wider text area and make a JavaScript function to validate it.

http://stackoverflow.com/questions/4460 ... javascript

nuBuilder has no built in format for that.

Steven
ruiascensao
Posts: 177
Joined: Tue Nov 15, 2011 2:24 pm

Re: Date and Time

Unread post by ruiascensao »

Hi Steven,

I am using in the form "before open":

Code: Select all

$sql = "SELECT CURDATE() AS date";
$result = nuRunQuery($sql);
$date = db_fetch_object($result);
$date = date("d-M-Y");

$javascript = " function  nuLoadThis() {\n";
$javascript .= " if (document.getElementById('unit_date').value == ''){\n";
$javascript .= " document.getElementById('unit_date').value = '".$date."';\n";
$javascript .= "}}\n";
addJSFunction($javascript);
Result is not correct! I get tomorrows date.

If I use:

Code: Select all

$sql = "SELECT now() AS date";
$result = nuRunQuery($sql);
$date = db_fetch_object($result);
$date = date("d-M-Y H:i:s");

$javascript = " function  nuLoadThis() {\n";
$javascript .= " if (document.getElementById('unit_date').value == ''){\n";
$javascript .= " document.getElementById('unit_date').value = '".$date."';\n";
$javascript .= "}}\n";
addJSFunction($javascript);


... the now() function doesn't work!

Any idea why is not working? I have checked the dates in my systems and are correct.

Thank you!
Best regards,
Rui
BR
Rui
MichaelD
Posts: 2
Joined: Wed Apr 04, 2012 11:08 am

Re: Date and Time

Unread post by MichaelD »

Rui,
are you sure you have set the correct timezone (+date) on your MySQL Server?
ruiascensao
Posts: 177
Joined: Tue Nov 15, 2011 2:24 pm

Re: Date and Time

Unread post by ruiascensao »

Hi MichaelD,

Yes it is correct:

mysql> SELECT CURDATE() AS date;
+------------+
| date |
+------------+
| 2012-04-17 |
+------------+
1 row in set (0.00 sec)
-----

Any other idea?

Best Regards,
Rui
BR
Rui
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Date and Time

Unread post by admin »

Rui,

this will give you date and time

Code: Select all


$sql   = "SELECT now() AS date";
$table = nuRunQuery($sql);
$row   = db_fetch_row($table);
$date  = $row[0];

Steven
ruiascensao
Posts: 177
Joined: Tue Nov 15, 2011 2:24 pm

Re: Date and Time

Unread post by ruiascensao »

Thank You Steven!
It's working.

Best Regards,
Rui
BR
Rui
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Date and Time

Unread post by admin »

.
Locked