Skip to main content
Inspiring
Feb 15, 2007 4:18 PM UTC
Question

SQL date in PHP?

I have a SQL date field. I want to insert the current date and time into
it. What format option would I use for the PHP date() function?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



This topic is closed to new replies. Start a new post to keep the conversation going.

22 replies

Inspiring
Feb 15, 2007 5:41 PM UTC
It works fine like this -

<input name="textfield" type="hidden" value="<?php date('Y-m-d H:i:s'); ?>"
/>

when that field is being inserted into a SQL DATETIME field.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"PizzaGood" <PizzaGood@earthlink.com> wrote in message
news:er252n$1j3$1@forums.macromedia.com...
>I don't do PHP, but in ASP I use this as the default value of a hidden text
>field on forms:
>
> <input name="textfield" type="hidden" value="<%=now()%>">
>
> and then I just insert the record. I only do this if I do not want the
> actual server time, if I want the server time I set the default of the
> field on the actual sql server table/field.
>
> Would PHP be something like this?????
>
> <!--#echo var="DATE_LOCAL"-->
>
>
>
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:er2442$dc$1@forums.macromedia.com...
>>I am inserting a form's data into a SQL table. One of the fields in the
>>table is a Date field. How do I format the field in the form using PHP so
>>that I get the date and time in that SQL date field?
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "PizzaGood" <PizzaGood@earthlink.com> wrote in message
>> news:er23ig$t4f$1@forums.macromedia.com...
>>> Are you doing this on the SQL Server table as in a Default Value for the
>>> field?
>>>
>>> If so the date should not be truncated .
>>>
>>>
>>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>>> news:er2319$sgg$1@forums.macromedia.com...
>>>> It does work, but the time value is truncated off?
>>>>
>>>> --
>>>> Murray --- ICQ 71997575
>>>> Adobe Community Expert
>>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>>> ==================
>>>> http://www.dreamweavermx-templates.com - Template Triage!
>>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>>> ==================
>>>>
>>>>
>>>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>>>> news:er22o1$s1s$1@forums.macromedia.com...
>>>>> If I insert a field containing date("Y-m-d H:i:s") as its value into a
>>>>> SQL field with the Date format, will that work?
>>>>>
>>>>> --
>>>>> Murray --- ICQ 71997575
>>>>> Adobe Community Expert
>>>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>>>> ==================
>>>>> http://www.dreamweavermx-templates.com - Template Triage!
>>>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>>>> ==================
>>>>>
>>>>>
>>>>> "gareth" <support@nospam_phploginsuite.co.uk> wrote in message
>>>>> news:er226o$rb2$1@forums.macromedia.com...
>>>>>> As David said, NOW() will work in the SQL as the field value.
>>>>>>
>>>>>> Alternatively, if you want to use the PHP date command, the correct
>>>>>> format for date is:
>>>>>>
>>>>>> date("Y-m-d")
>>>>>>
>>>>>> date and time is:
>>>>>>
>>>>>> date("Y-m-d H:i:s")
>>>>>>
>>>>>> --
>>>>>> Gareth
>>>>>> http://www.phploginsuite.co.uk/
>>>>>> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login
>>>>>> system.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Translate
Inspiring
Feb 15, 2007 5:27 PM UTC
Duh - that'd do it. Thanks!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"gareth" <support@nospam_phploginsuite.co.uk> wrote in message
news:er24sb$1e4$1@forums.macromedia.com...
>A DATE field holds just the date. If you want date and time change to the
>DATETIME data type.
>
> --
> Gareth
> http://www.phploginsuite.co.uk/
> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
>
>
>


Translate
Inspiring
Feb 15, 2007 5:25 PM UTC
I don't do PHP, but in ASP I use this as the default value of a hidden text
field on forms:

<input name="textfield" type="hidden" value="<%=now()%>">

and then I just insert the record. I only do this if I do not want the
actual server time, if I want the server time I set the default of the field
on the actual sql server table/field.

Would PHP be something like this?????

<!--#echo var="DATE_LOCAL"-->




"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:er2442$dc$1@forums.macromedia.com...
>I am inserting a form's data into a SQL table. One of the fields in the
>table is a Date field. How do I format the field in the form using PHP so
>that I get the date and time in that SQL date field?
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "PizzaGood" <PizzaGood@earthlink.com> wrote in message
> news:er23ig$t4f$1@forums.macromedia.com...
>> Are you doing this on the SQL Server table as in a Default Value for the
>> field?
>>
>> If so the date should not be truncated .
>>
>>
>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>> news:er2319$sgg$1@forums.macromedia.com...
>>> It does work, but the time value is truncated off?
>>>
>>> --
>>> Murray --- ICQ 71997575
>>> Adobe Community Expert
>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>> ==================
>>> http://www.dreamweavermx-templates.com - Template Triage!
>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>> ==================
>>>
>>>
>>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>>> news:er22o1$s1s$1@forums.macromedia.com...
>>>> If I insert a field containing date("Y-m-d H:i:s") as its value into a
>>>> SQL field with the Date format, will that work?
>>>>
>>>> --
>>>> Murray --- ICQ 71997575
>>>> Adobe Community Expert
>>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>>> ==================
>>>> http://www.dreamweavermx-templates.com - Template Triage!
>>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>>> ==================
>>>>
>>>>
>>>> "gareth" <support@nospam_phploginsuite.co.uk> wrote in message
>>>> news:er226o$rb2$1@forums.macromedia.com...
>>>>> As David said, NOW() will work in the SQL as the field value.
>>>>>
>>>>> Alternatively, if you want to use the PHP date command, the correct
>>>>> format for date is:
>>>>>
>>>>> date("Y-m-d")
>>>>>
>>>>> date and time is:
>>>>>
>>>>> date("Y-m-d H:i:s")
>>>>>
>>>>> --
>>>>> Gareth
>>>>> http://www.phploginsuite.co.uk/
>>>>> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login
>>>>> system.
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Translate
Inspiring
Feb 15, 2007 5:22 PM UTC
A DATE field holds just the date. If you want date and time change to the
DATETIME data type.

--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.



Translate
Inspiring
Feb 15, 2007 5:09 PM UTC
I am inserting a form's data into a SQL table. One of the fields in the
table is a Date field. How do I format the field in the form using PHP so
that I get the date and time in that SQL date field?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"PizzaGood" <PizzaGood@earthlink.com> wrote in message
news:er23ig$t4f$1@forums.macromedia.com...
> Are you doing this on the SQL Server table as in a Default Value for the
> field?
>
> If so the date should not be truncated .
>
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:er2319$sgg$1@forums.macromedia.com...
>> It does work, but the time value is truncated off?
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
>> news:er22o1$s1s$1@forums.macromedia.com...
>>> If I insert a field containing date("Y-m-d H:i:s") as its value into a
>>> SQL field with the Date format, will that work?
>>>
>>> --
>>> Murray --- ICQ 71997575
>>> Adobe Community Expert
>>> (If you *MUST* email me, don't LAUGH when you do so!)
>>> ==================
>>> http://www.dreamweavermx-templates.com - Template Triage!
>>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>>> ==================
>>>
>>>
>>> "gareth" <support@nospam_phploginsuite.co.uk> wrote in message
>>> news:er226o$rb2$1@forums.macromedia.com...
>>>> As David said, NOW() will work in the SQL as the field value.
>>>>
>>>> Alternatively, if you want to use the PHP date command, the correct
>>>> format for date is:
>>>>
>>>> date("Y-m-d")
>>>>
>>>> date and time is:
>>>>
>>>> date("Y-m-d H:i:s")
>>>>
>>>> --
>>>> Gareth
>>>> http://www.phploginsuite.co.uk/
>>>> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login
>>>> system.
>>>>
>>>
>>>
>>
>>
>
>


Translate
Inspiring
Feb 15, 2007 5:00 PM UTC
Are you doing this on the SQL Server table as in a Default Value for the
field?

If so the date should not be truncated .


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:er2319$sgg$1@forums.macromedia.com...
> It does work, but the time value is truncated off?
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
> news:er22o1$s1s$1@forums.macromedia.com...
>> If I insert a field containing date("Y-m-d H:i:s") as its value into a
>> SQL field with the Date format, will that work?
>>
>> --
>> Murray --- ICQ 71997575
>> Adobe Community Expert
>> (If you *MUST* email me, don't LAUGH when you do so!)
>> ==================
>> http://www.dreamweavermx-templates.com - Template Triage!
>> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
>> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
>> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
>> ==================
>>
>>
>> "gareth" <support@nospam_phploginsuite.co.uk> wrote in message
>> news:er226o$rb2$1@forums.macromedia.com...
>>> As David said, NOW() will work in the SQL as the field value.
>>>
>>> Alternatively, if you want to use the PHP date command, the correct
>>> format for date is:
>>>
>>> date("Y-m-d")
>>>
>>> date and time is:
>>>
>>> date("Y-m-d H:i:s")
>>>
>>> --
>>> Gareth
>>> http://www.phploginsuite.co.uk/
>>> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login
>>> system.
>>>
>>
>>
>
>


Translate
Inspiring
Feb 15, 2007 4:50 PM UTC
It does work, but the time value is truncated off?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:er22o1$s1s$1@forums.macromedia.com...
> If I insert a field containing date("Y-m-d H:i:s") as its value into a SQL
> field with the Date format, will that work?
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.dreamweavermx-templates.com - Template Triage!
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
> ==================
>
>
> "gareth" <support@nospam_phploginsuite.co.uk> wrote in message
> news:er226o$rb2$1@forums.macromedia.com...
>> As David said, NOW() will work in the SQL as the field value.
>>
>> Alternatively, if you want to use the PHP date command, the correct
>> format for date is:
>>
>> date("Y-m-d")
>>
>> date and time is:
>>
>> date("Y-m-d H:i:s")
>>
>> --
>> Gareth
>> http://www.phploginsuite.co.uk/
>> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login
>> system.
>>
>
>


Translate
Inspiring
Feb 15, 2007 4:45 PM UTC
If I insert a field containing date("Y-m-d H:i:s") as its value into a SQL
field with the Date format, will that work?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"gareth" <support@nospam_phploginsuite.co.uk> wrote in message
news:er226o$rb2$1@forums.macromedia.com...
> As David said, NOW() will work in the SQL as the field value.
>
> Alternatively, if you want to use the PHP date command, the correct format
> for date is:
>
> date("Y-m-d")
>
> date and time is:
>
> date("Y-m-d H:i:s")
>
> --
> Gareth
> http://www.phploginsuite.co.uk/
> PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.
>


Translate
Inspiring
Feb 15, 2007 4:36 PM UTC
As David said, NOW() will work in the SQL as the field value.

Alternatively, if you want to use the PHP date command, the correct format
for date is:

date("Y-m-d")

date and time is:

date("Y-m-d H:i:s")

--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.


Translate
Inspiring
Feb 15, 2007 4:32 PM UTC
I want to load a form with the value of the date and time to be inserted
into a Date field in MySQL. That's the scenario.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"David Powers" <david@example.com> wrote in message
news:er21jr$qhv$1@forums.macromedia.com...
> Murray *ACE* wrote:
>> I have a SQL date field. I want to insert the current date and time into
>> it. What format option would I use for the PHP date() function?
>
> If you want to insert the current date and time in MySQL, just use the
> NOW() function.
>
> --
> David Powers, Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "PHP Solutions" (friends of ED)
> http://foundationphp.com/


Translate