Controlling your dates
How do I make my date in a hidden form element so that it inserts properly in a UK timezone date field ?
There are several ways to achieve this, but to have the most control of the format try building it yourself with the date functions available, here is an example of a UK date stuck into a hidden form element:
In the head you place this code:
varUKdate = DAY(Date()) &"/"& MONTH(Date()) &"/"& YEAR(Date())
And in your body, between the form elements you place this hidden form element:
<input name="UKdate" type="hidden" value="<%= varUKdate%>">
And voila, instant UK date in a form element.
This next trick is SQL Server only (?):
There is however another way of getting now() in your date field, let's assume we have a html editor in a form which inserts and updates database records that are displayed, both update and insert are seperate pages called NewArticle.asp and EditArticle.asp.
NewArticle.asp does a insert without dates, the database handles the date tracking by use of the default Date() value that is specified in the design view of the table Articles.
EditArticle.asp, however, has the same form layout but an additional hiddenelement with NOTHING inside it, not even a space ! The page has the normal update behavior applied to it with data type set to Date in the behavior window, the following piece of code was created:
var MM_editConnection = MM_connWebApplication_STRING;
var MM_editTable = "Articles";
var MM_editColumn = "pageID";
var MM_recordId = "" + Request.Form("MM_recordId") + "";
var MM_editRedirectUrl = "articles.asp";
var MM_fieldsStr = "frmTitel|value|checkbox|value|EditorValue|value|hiddenDate|value";
var MM_columnsStr = "PageTitle|',none,''|PageArchive|none,1,0|PageContent|',none,''|PageUpdated|',none,NULL";
Note the last two var commands, they declare what goes where, notice the NULL in the date, if you execute this you will notice what the NULL does if your date column will not allow NULLS to be entered. Here is the trick, change NULL to DEFAULT. DEFAULT is a reserved word, your database will catch it and translate it as "update articles set PageUpdated to default value where PageID = whatever". Just change the last bit to resemble this code:
And by now you might think that is fantastic, i can now insert and update datetime fields using the default date() method, so there is no more need for lousy server code to deal with dates in my format. But you will soon get over that when you want to continue spoiling your clients.
This, BTW, works more accurate than doing now() or date() in your form element, because this date is created when the article is actually being submitted to the database and not when the user requests the form from the server and takes maybe minutes or longer to update it and sending the timestamp along that was created when the server was building the edit page.
Have fun playing with SQL commands !