1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Date format

Discussion in 'C#' started by apollon, Apr 21, 2006.

  1. #1
    hi,
    I using ASP page with MS Access 2003 db.
    I have the following problem.

    When i try to insert new record my date is wrong.
    for example when i write 21/5/2000 the record inserted as
    21/5/2000 but when i write 3/6/2000 displays as 06/03/2000.
    The only way that works is to write for example 3/apr/2000 or 21/apr/2000 and its ok but i dont want this format.

    *Note that the CDate field in db is text format.

    Please check my code below:
    if request.form("txtCDate")="" then
    sqlCDate="Null"
    else
    sqlCDate="#" & request.form("txtCDate") & "#"
    end if
    strSql="Insert into [Task](Category,CDate) values('InternalTask'" & "," & sqlCDate & ")"


    My regional settings its ok.(United Kingdom).

    Please can anyone helpme to find the problem?

    Thanks a lot
     
    apollon, Apr 21, 2006 IP
  2. doronty37

    doronty37 Active Member

    Messages:
    130
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    you can use this function to format the appearance of date, the db value format is text or anything else.

    <%
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' Format date function
    ' Murat.Yavuz a.k.a doronty37
    ' W: http://www.mydesign.gen.tr
    ' @: mydesign@mydesign.gen.tr
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Function FormatDate(ByVal strDate)
    
    	'// If variable is empty, exit function
    	If strDate = "" Or isDate(strDate) = False Then Exit Function
    
    	blnHour = False '// If you want to show hour, change this value as True
    
    	'// Getting values from variable
    	intSecond = Second(strDate)
         	intMinute = Minute(strDate)
         	intHour = Hour(strDate)
         	intDay = Day(strDate)
         	intMonth = Month(strDate)
         	intYear = Year(strDate)
    
         	'// Adding 0 to the front if lenght is less than 2 
         	If Len(intMonth) < 2 Then intMonth="0" & intMonth
         	If Len(intDay) < 2 Then intDay="0" & intDay
         	If Len(intHour) < 2 Then intHour="0" & intHour
         	If Len(intMinute) < 2 Then intMinute="0" & intMinute
         	If Len(intSecond) < 2 Then intSecond="0" & intSecond
    
         	'// Remove hour part if the is no hour in variable
         	If intSecond = "00" And intMinute = "00" And intHour = "00" Then blnHour = False
         	FormatDate = intMonth &"/"& intDay &"/"& intYear &"
         	If blnHour Then FormatDate = FormatDate &"&nbsp;"& intHour &":"& intMinute &":"& intSecond
    
    End Function
    %>
    Code (markup):
     
    doronty37, Apr 21, 2006 IP
  3. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #3
    you should just convert the month to the text name, like 03/apr/06 before each instert, and prevent any errors. That's probably the fastest resolution
     
    frankcow, Apr 21, 2006 IP