Forums
This topic is locked
Inserting Current Date
23 Jul 2001 13:04:49 Alain Uy posted:
im new and very confused of how to insert the current or local date to my database, im using the server behavior insert feature of ud4 but how can i also insert the current date without the entering the current date to the database automatically..Replies
Replied 23 Jul 2001 14:51:52
23 Jul 2001 14:51:52 Bruno Mairlot replied:
blitzkin,
I have posted a PHP Date extension (on DW Exchange).
This is not linked to Phakt or UD in any way, but it lets you the possibility to format a date into a variable.
Of course this is if you're using PHP as a server side scripting language.
Otherwise, if you wish to include a current date into your insert query, here is a schema independant of the language :
1. Get the date into a variable.
In php you could do it with $date=getdate()
In ASP,JSP or CF, it should work too but you'll have to check the doc
2. Construct your query depending on the date. When you're creating a insert behavior, in the code you'll have something that looks like :
<b>$query="insert into mytable (ID,texte) VALUES (NULL,'sjdkfjkl')";</b>
Then modify this piece of code to enter the date field, like this :
<b>$query="insert into mytable (ID,texte,date) VALUES (NULL,'sjdkfjkl',$date)";</b>
And you're on !
I have posted a PHP Date extension (on DW Exchange).
This is not linked to Phakt or UD in any way, but it lets you the possibility to format a date into a variable.
Of course this is if you're using PHP as a server side scripting language.
Otherwise, if you wish to include a current date into your insert query, here is a schema independant of the language :
1. Get the date into a variable.
In php you could do it with $date=getdate()
In ASP,JSP or CF, it should work too but you'll have to check the doc
2. Construct your query depending on the date. When you're creating a insert behavior, in the code you'll have something that looks like :
<b>$query="insert into mytable (ID,texte) VALUES (NULL,'sjdkfjkl')";</b>
Then modify this piece of code to enter the date field, like this :
<b>$query="insert into mytable (ID,texte,date) VALUES (NULL,'sjdkfjkl',$date)";</b>
And you're on !
Replied 24 Jul 2001 06:02:29
24 Jul 2001 06:02:29 Alain Uy replied:
thanks sir, actually im not using php scripting but regarding the variable passing maybe ill deal with that... thanks alot..
Replied 27 Jul 2001 17:54:58
27 Jul 2001 17:54:58 e site replied:
Just a quick thought for you;
in ASP you do this in the DBase itself with a standard value "Now()"
No hassle with scripts 'n extensions!
Couldn't you do this to?
e_site
in ASP you do this in the DBase itself with a standard value "Now()"
No hassle with scripts 'n extensions!
Couldn't you do this to?
e_site
Replied 27 Jul 2001 21:10:47
27 Jul 2001 21:10:47 George Petrov replied:
Now() is just for Access
If you use SQL Server you should use GETDATE() in your database as default value
---------------------------------------
George Petrov - CTO, www.UDzone.com
www.UDzone.com : A Dreamweaver,
Dreamweaver Ultradev and Fireworks site
by developers for developers.
---------------------------------------
If you use SQL Server you should use GETDATE() in your database as default value
---------------------------------------
George Petrov - CTO, www.UDzone.com
www.UDzone.com : A Dreamweaver,
Dreamweaver Ultradev and Fireworks site
by developers for developers.
---------------------------------------
Replied 29 Jul 2001 16:52:27
29 Jul 2001 16:52:27 Alain Uy replied:
the now() is great but it displays all the info the date and TIME, thus when i tried to query the db using the date field i have to also include the time, (which means that i need to enter the whole string).. i only want the date... i already set the format in access but still the same
Replied 29 Jul 2001 17:14:33
29 Jul 2001 17:14:33 Bruno Mairlot replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
the now() is great but it displays all the info the date and TIME, thus when i tried to query the db using the date field i have to also include the time, (which means that i need to enter the whole string).. i only want the date... i already set the format in access but still the same
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
If now() works on your system, its a great step. Now you have to find API functions that will split the full datetime info into smaller parts like year,month,day of month...
I've tried on my Access 2002, and it seems to be very simple : it is year,month,day
Here is the query I build with Access : <pre id=code><font face=courier size=2 id=code>
SELECT Year(hist_crp.date) AS Expr1, Month([date]) AS Expr3, Day([date]) AS Expr2, Year(now())
FROM hist_crp;
</font id=code></pre id=code>
And it worked fine. Hope it helps
"First they laugh at you, then they fight you, then you Win..." Ghandi
the now() is great but it displays all the info the date and TIME, thus when i tried to query the db using the date field i have to also include the time, (which means that i need to enter the whole string).. i only want the date... i already set the format in access but still the same
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
If now() works on your system, its a great step. Now you have to find API functions that will split the full datetime info into smaller parts like year,month,day of month...
I've tried on my Access 2002, and it seems to be very simple : it is year,month,day
Here is the query I build with Access : <pre id=code><font face=courier size=2 id=code>
SELECT Year(hist_crp.date) AS Expr1, Month([date]) AS Expr3, Day([date]) AS Expr2, Year(now())
FROM hist_crp;
</font id=code></pre id=code>
And it worked fine. Hope it helps
"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 29 Jul 2001 17:33:35
29 Jul 2001 17:33:35 Alain Uy replied:
sir, seems a little complex for me (the code) but i will try to isolate the problem and im only using ofc2k.. thanks for the logic sir
Replied 16 Aug 2001 16:31:08
16 Aug 2001 16:31:08 Owen Eastwick replied:
Am I to understand that you simply want the current date in a field within a database table?
For Example:
You insert a new Order into the Orders Table and you want provide the current date as the Order Date when the new record is created.
ORDERS TABLE
<b>OrderID ProductID Quantity OrderDate</b>
23 5674 3 28/07/2001
24 8765 7 29/07/2001
etc...
You could do this in Access. Create the Date Field in your Database table with a Data Type of <b>Date/Time</b>. Next give it a Format of <b>Short Date</b> (or whatever you require) then set the default value to <b>Now()</b>
Now whenever you add a record to the table the date field will be completed with the current date.
So if you are using Insert Record server behavior on the ASP page, insert everything you require into the table and the Database will take care of providing the curent date. In my example Orders table you would just insert the ProductID and the Quantity.
Regards
Owen.
Edited by - oeastwick on 08/16/2001 16:33:54
For Example:
You insert a new Order into the Orders Table and you want provide the current date as the Order Date when the new record is created.
ORDERS TABLE
<b>OrderID ProductID Quantity OrderDate</b>
23 5674 3 28/07/2001
24 8765 7 29/07/2001
etc...
You could do this in Access. Create the Date Field in your Database table with a Data Type of <b>Date/Time</b>. Next give it a Format of <b>Short Date</b> (or whatever you require) then set the default value to <b>Now()</b>
Now whenever you add a record to the table the date field will be completed with the current date.
So if you are using Insert Record server behavior on the ASP page, insert everything you require into the table and the Database will take care of providing the curent date. In my example Orders table you would just insert the ProductID and the Quantity.
Regards
Owen.
Edited by - oeastwick on 08/16/2001 16:33:54
Replied 19 Aug 2001 10:37:35
19 Aug 2001 10:37:35 Alain Uy replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Am I to understand that you simply want the current date in a field within a database table?
For Example:
You insert a new Order into the Orders Table and you want provide the current date as the Order Date when the new record is created.
ORDERS TABLE
<b>OrderID ProductID Quantity OrderDate</b>
23 5674 3 28/07/2001
24 8765 7 29/07/2001
etc...
You could do this in Access. Create the Date Field in your Database table with a Data Type of <b>Date/Time</b>. Next give it a Format of <b>Short Date</b> (or whatever you require) then set the default value to <b>Now()</b>
Now whenever you add a record to the table the date field will be completed with the current date.
So if you are using Insert Record server behavior on the ASP page, insert everything you require into the table and the Database will take care of providing the curent date. In my example Orders table you would just insert the ProductID and the Quantity.
Regards
Owen.
Edited by - oeastwick on 08/16/2001 16:33:54
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote><font face='Verdana'></font id='Verdana'><img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle> thats it!!! cool i have tried to do that with the access now() and atlast im free!!!!! hnehehehe thanks to all the people who have shared with this little problem of mine... really Thanks..!!<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
Am I to understand that you simply want the current date in a field within a database table?
For Example:
You insert a new Order into the Orders Table and you want provide the current date as the Order Date when the new record is created.
ORDERS TABLE
<b>OrderID ProductID Quantity OrderDate</b>
23 5674 3 28/07/2001
24 8765 7 29/07/2001
etc...
You could do this in Access. Create the Date Field in your Database table with a Data Type of <b>Date/Time</b>. Next give it a Format of <b>Short Date</b> (or whatever you require) then set the default value to <b>Now()</b>
Now whenever you add a record to the table the date field will be completed with the current date.
So if you are using Insert Record server behavior on the ASP page, insert everything you require into the table and the Database will take care of providing the curent date. In my example Orders table you would just insert the ProductID and the Quantity.
Regards
Owen.
Edited by - oeastwick on 08/16/2001 16:33:54
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote><font face='Verdana'></font id='Verdana'><img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle> thats it!!! cool i have tried to do that with the access now() and atlast im free!!!!! hnehehehe thanks to all the people who have shared with this little problem of mine... really Thanks..!!<img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>