Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2004, 03:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default date format in ASP ?


How can retrieve date format yyyy/mm/dd format in ASP ?

Date save in sql server yyyy/mm/dd format when I retrieve date in asp ie. strdate

asp page retrieve date format mm/dd/yyyy why ?

at the time of data entry, in same format date save and
same format date retrieve in asp page?


<TR>
    <TD>Start Date (yyyy/mm/dd)</TD>
    <TD><%Response.Write("<INPUT id=strdate name=strdate value='" & rs("strdate") &"'>")%></TD></TR>
  <TR>


Regards.

Mateen


 
Old February 11th, 2004, 07:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Mateen,

You can use it this way.

Code:
Year(rs("strdate")) & "/" & Month(rs("strdate")) & "/" & Day(rs("strdate"))
Replace the
Code:
rs("strdate")
within the INPUT tag, with the code given above.

Cheers,

-Vijay G
 
Old February 12th, 2004, 01:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Vijay G


Quote:
quote:Originally posted by happygv
 Mateen,

You can use it this way.

Code:
Year(rs("strdate")) & "/" & Month(rs("strdate")) & "/" & Day(rs("strdate"))
Replace the
Code:
rs("strdate")
within the INPUT tag, with the code given above.

Cheers,

-Vijay G
 
Old February 14th, 2004, 02:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is problem in day/month/year format

I use your code like this

fieldData = Day(rs("appstrdate")) & "/" & Month(rs("appstrdate")) & "/" & Year(rs("appstrdate")) & ""
If Len(fieldData) = 0 Then fieldData = " - "
Response.Write("<td align=center>" & fieldData & "</td>")


When date is null it displaying // in the date column why ?

when date is null it should be displayed - in the date column ?

How can display date format if date is null it display - in the date column ?

Regards.

Mateen






Quote:
quote:Originally posted by mateenmohd
 Thanks Vijay G


Quote:
quote:Originally posted by happygv
 Mateen,

You can use it this way.

Code:
Year(rs("strdate")) & "/" & Month(rs("strdate")) & "/" & Day(rs("strdate"))
Replace the
Code:
rs("strdate")
within the INPUT tag, with the code given above.

Cheers,

-Vijay G
 
Old February 15th, 2004, 04:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Mateen,

You should check if the date column is null once you retrieve it from the database (using the recordset object). Thats is the right approach, instead of formatting it into "fieldData" and then checking if that is null. I am not sure what you would want to display when the date column returns null. So you can decide on it and act accordingly.

Cheers,



-Vijay G
 
Old February 15th, 2004, 06:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for response.

I was want that when date column returns null it display " - "
otherwise display date.

now I use your code like this.

fieldData = Day(rs("appstrdate")) & "/" & Month(rs("appstrdate")) & "/" & Year(rs("appstrdate")) & ""
If fieldData = "//" Then fieldData = "-"
Response.Write("<td align=center>" & fieldData & "</td>")

in the date columne date will enter, if date is null then it will
display " - "

now it is solve the problem.

Mateen



Quote:
quote:Originally posted by happygv
 Mateen,

You should check if the date column is null once you retrieve it from the database (using the recordset object). Thats is the right approach, instead of formatting it into "fieldData" and then checking if that is null. I am not sure what you would want to display when the date column returns null. So you can decide on it and act accordingly.

Cheers,



-Vijay G
 
Old February 18th, 2004, 04:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Vijay G

sorry for again.

how can use year/month/day format at the time of update the date
field. when date is null it display // why ?

ssql="strdate from contracts where contractno='"& contractno &"'"

set rs=cn.Execute(ssql)

<TR>
    <TD>Start Date (y/m/d)</TD>
<TD><%Response.Write("<INPUT ID=strdate name=strdate value='" & Year(rs("strdate")) & "/" & Month(rs("strdate")) & "/" & Day(rs("strdate")) & "'>")%></td></tr>


I controll this when date have to display (previous coding). when date to update (edit) how can solve this.

it should not display // at the update date field ?

OR

How can check at the time of retrieve the date from the database
(using the recordset object),
if date if null it display null otherwise display date ?

Regards.

Mateen



Quote:
quote:Originally posted by happygv
 Mateen,

You should check if the date column is null once you retrieve it from the database (using the recordset object). Thats is the right approach, instead of formatting it into "fieldData" and then checking if that is null. I am not sure what you would want to display when the date column returns null. So you can decide on it and act accordingly.

Cheers,



-Vijay G
 
Old February 19th, 2004, 09:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

That is because you first formatted the date and then trying to check if it is null. The same I have stated in my previous mail. You could check that this way.

<%
ssql="Select strdate from contracts where contractno='"& contractno &"'"

set rs=cn.Execute(ssql)
if not rs.EOF then
    If len(rs(DATEFIELD))>0 then
%>
        <TR>
            <TD>Start Date (y/m/d)</TD>
             <TD><%Response.Write("<INPUT ID=strdate name=strdate value='" & Year(rs("strdate")) & "/" & Month(rs("strdate")) & "/" & Day(rs("strdate")) & "'>")%></td></tr>

     <%else %>
        <TR>
        <TD>Start Date (y/m/d)</TD>
            <TD><%Response.Write("<INPUT ID=strdate name=strdate value=''>")%></td></tr>
<%
    end if
end if
%>

Hope this helps.

Cheers,

-Vijay G
 
Old February 22nd, 2004, 01:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot

Mateen

Quote:
quote:Originally posted by happygv
 That is because you first formatted the date and then trying to check if it is null. The same I have stated in my previous mail. You could check that this way.

<%
ssql="Select strdate from contracts where contractno='"& contractno &"'"

set rs=cn.Execute(ssql)
if not rs.EOF then
    If len(rs(DATEFIELD))>0 then
%>
        <TR>
            <TD>Start Date (y/m/d)</TD>
             <TD><%Response.Write("<INPUT ID=strdate name=strdate value='" & Year(rs("strdate")) & "/" & Month(rs("strdate")) & "/" & Day(rs("strdate")) & "'>")%></td></tr>

     <%else %>
        <TR>
        <TD>Start Date (y/m/d)</TD>
            <TD><%Response.Write("<INPUT ID=strdate name=strdate value=''>")%></td></tr>
<%
    end if
end if
%>

Hope this helps.

Cheers,

-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP Date Format apollon10 ASP.NET 3.5 Professionals 1 November 13th, 2007 05:54 AM
ASP/Access Date Format seananderson Classic ASP Databases 2 November 6th, 2006 02:15 PM
Date Format problem in ASP ppenn Classic ASP Databases 3 May 11th, 2004 06:35 PM
Setting date format from ASP.NET jonashilmersson Crystal Reports 0 November 14th, 2003 04:14 AM
MS Access and ASP : DATE Format failure Sebastiaan Classic ASP Basics 2 October 1st, 2003 12:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.