Solved

How to get a date to stay the right format

Posted on 2016-09-12
31
37 Views
Last Modified: 2016-09-21
Hi all, just wondering how I get the date to stay in the same format, no default

dd / mm / yy - this is the format I want to use

using ASP Classic and MS Access 2003

example date: 1/10/17
-everytime i update this is changes from 1/10/17 to 10/1/17 and then back.
0
Comment
Question by:Graeme
  • 16
  • 13
  • 2
31 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794125
you can use the FormatDateTime function, but that'll still give a for character year, so maybe a custom function would be better:

function customFormatDate( d )
     customFormatDate = padZero( Day( d ) & "/" & padZero( Month( d ) & "/" & Right( padZero( Year( d ), 2 )
end function

Open in new window


and you would call it like:

Response.Write customFormateDate( now )
0
 

Author Comment

by:Graeme
ID: 41794212
4 character year is fine for me, FormatDateTime ill try out and get back to you

cheers
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794219
ok, it should work the way you want to as long as your server date format settings are dd/mm/yyyy.

example:

Response.Write FormatDateTime( now, 2 )
0
 

Author Comment

by:Graeme
ID: 41794221
Just looking at FormatDateTime here: http://www.w3schools.com/asp/func_formatdatetime.asp

not seeing dd / mm / yyyy ??

I only see mm / dd / yyyy
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794228
I believe the format is based off of your local servers date/time locale settings. Give it a shot and see what happens!
1
 

Author Comment

by:Graeme
ID: 41794277
Still does the same

would I have to put it on the Response.Write ? or the Executed Query? or both?

I currently have it on the Executed Query
0
 

Author Comment

by:Graeme
ID: 41794284
also tried putting it on the Response.Write, same thing too
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794330
I would set it as its own variable, then use that in your query.

Did you try the custom function I gave you?
0
 

Author Comment

by:Graeme
ID: 41794334
would it matter with the date...

<input type=text> put in the there and submitted, when you go back to update it, that is when it changes, and you can keep clicking update and it changes around
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794340
can you post your updated code?
0
 

Author Comment

by:Graeme
ID: 41794346
oConn.Execute("UPDATE events SET event_name='"&Request.Form("eventname")&"',event_start=#"&FormatDateTime(Request.Form("eventstart"),2)&"#,event_finish=#"&FormatDateTime(Request.Form("eventfinish"),2)&"#,event_location="&GPLocations("location_ID")&",event_code='"&Request.Form("codeID")&"',event_conf="&EventConf&",event_live="&EventLive&" WHERE event_ID="&Request.QueryString("event"))

Open in new window

0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794362
if you do:

Response.Write "UPDATE events SET event_name='"&Request.Form("eventname")&"',event_start=#"&FormatDateTime(Request.Form("eventstart"),2)&"#,event_finish=#"&FormatDateTime(Request.Form("eventfinish"),2)&"#,event_location="&GPLocations("location_ID")&",event_code='"&Request.Form("codeID")&"',event_conf="&EventConf&",event_live="&EventLive&" WHERE event_ID="&Request.QueryString("event"))

then, whatever is outputted to the screen, run directly in your database and see if you get any results
0
 

Author Comment

by:Graeme
ID: 41794413
have been running it in my database, however because it is an UPDATE query, it doesnt produce a result?

however when it updates the DB, it changes it back and forth from 1/10/2017 to 10/1/2017 and vv
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794446
even when using my custom function?

oConn.Execute("UPDATE events SET event_name='"&Request.Form("eventname")&"',event_start=#"&customFormatDate(Request.Form("eventstart"))&"#,event_finish=#"&customFormatDate(Request.Form("eventfinish"))&"#,event_location="&GPLocations("location_ID")&",event_code='"&Request.Form("codeID")&"',event_conf="&EventConf&",event_live="&EventLive&" WHERE event_ID="&Request.QueryString("event"))
0
 

Author Comment

by:Graeme
ID: 41794448
going to try the custom function now
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Accepted Solution

by:
Graeme earned 0 total points
ID: 41794546
just having a look at some other code I have...

the difference between  ' " & 1/10/2017 & " ' and # " & 1/10/2017 & " # ??
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41794626
It should read using Format:
oConn.Execute("UPDATE events SET event_name='"&Request.Form("eventname")&"',event_start=#"&Format(Request.Form("eventstart"),"yyyy\/mm\/dd")&"#,event_finish=#"&Format(Request.Form("eventfinish"),"yyyy\/mm\/dd")&"#,event_location="&GPLocations("location_ID")&",event_code='"&Request.Form("codeID")&"',event_conf="&EventConf&",event_live="&EventLive&" WHERE event_ID="&Request.QueryString("event"))

Open in new window

/gustav
0
 

Author Comment

by:Graeme
ID: 41794630
Hi Gustav, this will insert the date as dd / mm / yyyy ?
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794649
Format() won't work, it's a visual basic function, not vbscript.

To answer your previous question, you should surround the date with pound signs
0
 

Author Comment

by:Graeme
ID: 41794654
Ah ok, I know I have a couple of other statements with the single quotes, but they are INSERTS
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41794657
Well, what do you see?

I don't know what you read from the form. You may have to apply DateValue as well:

    event_finish=#"&Format(DateValue(Request.Form("eventfinish")),"yyyy\/mm\/dd")&"#,

/gustav
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794699
again, there is no FORMAT() function in classic asp, you need to use formatDateTime(), as I suggested earlier. or use the custom function I gave you.

Did you try that? what were your results? I can't help you if you don't respond to the questions/solutions I propose
0
 

Author Comment

by:Graeme
ID: 41794742
Hi BigMonty, sorry I was trying to figure out where the missing brackets went, got that sorted.

Error now:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'padZero'

/admin2.asp, line 9 -> customFormatDate = padZero( Day( d ) )& "/" & padZero( Month( d ) )& "/" & Right( padZero( Year( d ), 2 ))

Open in new window

0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794754
dd this function anywhere on your page:

    function padZero( n )
        if CInt( n ) < n then
            padZero = "0" & n
        else
            padZero = n
        end if
    end function
0
 

Author Comment

by:Graeme
ID: 41794780
I have just tried replacing # with quotes and it inserts and doesn't change on recall and update... its working... ? is this supposed to happen? with quote and not # ?
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794791
the best way to tell if it's working is to see if the data is there in the database and in the format you want :)
0
 

Author Comment

by:Graeme
ID: 41794811
yeah its all working great, no issues at all

why would there be a difference?
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41794837
not sure why, both formats should have worked
0
 

Author Comment

by:Graeme
ID: 41795395
Interesting... how do we close off this question now?

I mean you have been a help is debugging it and trying different stuff...
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 41795973
i can't tell you how to close a question, I think EE may object to that :)

if any of my answers helped you and you think they may be useful to others, then select them. if not, delete the question and it'll auto-delete in 4 days.

FYI - I'm not here for the points, so as long as you got the solution, I don't care how :)
0
 

Author Closing Comment

by:Graeme
ID: 41808397
tried something not suggested and worked
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now