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
ASP formatdatetime
|
|
Mar 1 2006, 07:02 PM, updated 20y ago
Show posts by this member only | Post
#1
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
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 |
|
|
|
|
|
Mar 2 2006, 08:55 AM
Show posts by this member only | Post
#2
|
![]() ![]() ![]() ![]() ![]()
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... |
|
|
Mar 2 2006, 10:15 AM
Show posts by this member only | Post
#3
|
![]() ![]() ![]() ![]()
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. |
|
|
Mar 2 2006, 01:53 PM
Show posts by this member only | Post
#4
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
All Stars
21,256 posts Joined: Jan 2003 From: Pekopon |
visual basic
format(now,"dd-mm-yyyy") C# now.toString("dd-mm-yyyy"); |
|
|
Mar 2 2006, 02:10 PM
Show posts by this member only | Post
#5
|
![]() ![]() ![]() ![]() ![]() ![]() ![]()
Senior Member
4,607 posts Joined: Jan 2003 From: Malaysia |
|
|
|
Mar 2 2006, 02:52 PM
Show posts by this member only | Post
#6
|
![]() ![]() ![]() ![]() ![]()
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. |
|
|
|
|
|
Mar 2 2006, 02:55 PM
Show posts by this member only | Post
#7
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
All Stars
21,256 posts Joined: Jan 2003 From: Pekopon |
asp is Vb what
Format now working? |
|
|
Mar 2 2006, 03:06 PM
Show posts by this member only | Post
#8
|
![]() ![]() ![]() ![]()
Senior Member
571 posts Joined: Jan 2005 From: クアラー ルムポール |
|
|
|
Mar 2 2006, 03:34 PM
Show posts by this member only | Post
#9
|
![]() ![]() ![]() ![]() ![]()
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: | 0.0149sec
1.81
5 queries
GZIP Disabled
Time is now: 23rd December 2025 - 07:50 PM |