Page 1 of 1

Need date imput to be month-day-year

Posted: Sun Feb 24, 2013 11:16 pm
by JohnKlassen
Hi,

I have a report that prompts for a date range and then selects the correct data from #dataTable#.

Here is the code to get the date range from the form:

Code: Select all

$fromdate = reformatField($formValue['vFrom'], 11, $quotes = false);
$todate   = reformatField($formValue['vTo'], 11, $quotes = false);
I have formatted 'vFrom' and 'vto' as '13-01-2007'. Everything works with this format.

Since I live in the USA, I would like the format to be '01-13-2007'. I have tried various ways to make this work but have been unsuccessful.

Any suggestions?

John

Re: Need date imput to be month-day-year

Posted: Mon Feb 25, 2013 5:00 am
by admin
John,

What do you get just by using $formValue['vFrom']?

Steven

Re: Need date imput to be month-day-year

Posted: Tue Feb 26, 2013 5:50 am
by JohnKlassen
Steven,

I realize now that I have 2 different issues. The first is how to display the date in month-day-year to my user. The second is how to format the same date to year-month-day in my WHERE clause.

I resolved the month-day-year display on the form by setting the format in the text tab for vFrom to '01-13-2007' and using the following"

Code: Select all

$fromdate = $formValue['vFrom'];
as you suggested.

I have not figured out how to format the date as year-month-day so I can use it with BETWEEN date ranges. I tried "

Code: Select all

$yearfromdate = date("Y-m-d", $fromdate);
but the result for '01-16-2013' came out as '1970-01-01'.

Thanks for fixing the first problem. Any suggestions for the second one?

BTW, is there any documentation for some of these commands like 'reformat' so that I know what the pareameters are doing?

Thanks,

John

Re: Need date imput to be month-day-year

Posted: Tue Feb 26, 2013 7:00 am
by admin
John,

Here's the wiki link..

http://wiki.nubuilder.com/tiki-index.ph ... rmatField_

I suggest you refer to your fields with hash variables..

Code: Select all


print $formValue['vFrom'];

print '#vFrom#';  //-- use this instead

should give you - 13-01-2007

Code: Select all


$fromdate = reformatField('#vFrom#', 7);
$todate   = reformatField('#vTo#', 7);

$s = "SELECT * FROM invoice WHERE inv_date BETWEEN $fromdate AND $todate"
print $s;

should give you - SELECT * FROM invoice WHERE inv_date BETWEEN '2007-01-13' AND '2007-01-26'

Steven

Re: Need date imput to be month-day-year

Posted: Wed Feb 27, 2013 5:31 am
by JohnKlassen
Steven,

First of all, thanks for the link to the wiki page. I had looked at it a couple of months ago and had not thought about looking there.

Secondly, thanks for pointing me in the right direction. Since I have the default format for vfrom as '01-13-2007', I had to use reformat with option 9 or 13 to get 'Y-m-d'.

The good news is that it works.

Thanks,

John

Re: Need date imput to be month-day-year

Posted: Wed Feb 27, 2013 10:45 pm
by admin
Excellent!