Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 ASP formatdatetime

views
     
TSychwang
post Mar 1 2006, 07:02 PM, updated 20y ago

Little *
*******
Senior Member
4,607 posts

Joined: Jan 2003
From: Malaysia
How to format datetime to mysql format?
i want the time format to be yyyy-mm-dd hh:mm:ss

in vb6 i can use
CODE

mysqldate=format("YYYY-MM-DD HH:MM:SS", Now())


but in asp, format function is not usable.
Help
nxfx
post Mar 2 2006, 08:55 AM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


One way is to seperate the datetime and rebuild it as string.
If the date is like 03/02/2006 (MMDDYYYY) , break it to
DD = 02
MM = 03
YYYY = 2006

From here you can just manipulate the string.

mydate = DD & "-" & MM & "-" & YYYY
which looks like , 02-03-2006.

Just a suggestion anyway...
cikun
post Mar 2 2006, 10:15 AM

チクォン
****
Senior Member
571 posts

Joined: Jan 2005
From: クアラー ルムポール
dude, i thought the format function is like this:

Format(Now(), "dd MM yyyy")

notice Now() is before the desired format string. and be careful with the CASE. d is DAY, M for MONTH and m for minutes.

i'm trying this new thing i came out with. it's for .NET apps. dunno whether it's good or not. do try and give comments if you may.

CODE
   
   Private Function US_date_to_MY(ByVal tarikh As String) As String
       Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
       Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
       Return Format(CDate(tarikh), "dd MMM yyyy")
   End Function

   Private Function MY_date_to_US(ByVal str As String) As DateTime
       Thread.CurrentThread.CurrentCulture = New CultureInfo("ms-MY")
       Thread.CurrentThread.CurrentUICulture = New CultureInfo("ms-MY")
       Return str
   End Function


function US_date_to_MY accepts normal datetime and returns desired datetime format, dd MMM yyyy.

the other function accepts dd MMM yyyy (also works for various combinations as long as it's in d/M/y sequence).

so far as i tested, the functions work both in web and window apps.
shinchan^^
post Mar 2 2006, 01:53 PM

K66
*********
All Stars
21,256 posts

Joined: Jan 2003
From: Pekopon


visual basic

format(now,"dd-mm-yyyy")


C#

now.toString("dd-mm-yyyy");
TSychwang
post Mar 2 2006, 02:10 PM

Little *
*******
Senior Member
4,607 posts

Joined: Jan 2003
From: Malaysia
QUOTE(shinchan^^ @ Mar 2 2006, 01:53 PM)
visual basic

format(now,"dd-mm-yyyy")
C#

now.toString("dd-mm-yyyy");
*
how about asp? i'm using asp, and the format code doesnt work for asp.
nxfx
post Mar 2 2006, 02:52 PM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


How about my method?
I assume you want to save the datetime into your database, then how about formating it in the sql statement where the mysql has better formating option.
shinchan^^
post Mar 2 2006, 02:55 PM

K66
*********
All Stars
21,256 posts

Joined: Jan 2003
From: Pekopon


asp is Vb what

Format now working?
cikun
post Mar 2 2006, 03:06 PM

チクォン
****
Senior Member
571 posts

Joined: Jan 2005
From: クアラー ルムポール
QUOTE(nxfx @ Mar 2 2006, 02:52 PM)
...how about formating it in the sql statement where the mysql has better formating option.
*
can you pls ellaborate on that? formatting in a sql statement? you mean, calling for the desired format readily in a sql statement, using sql syntax?
nxfx
post Mar 2 2006, 03:34 PM

Enthusiast
*****
Senior Member
979 posts

Joined: Jan 2003


Emm, something like

mydate = "17/03/2004"

sql = "insert into Tbl(mydate) "
sql = sql & " values(convert(datetime, ' " & mydate & "', 103))"

But this done using mssql, dunno if mysql have the same function.

 

Change to:
| Lo-Fi Version
0.0169sec    0.40    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 07:45 AM