Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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 May 9th, 2008, 03:29 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date format

I'm in a big if a bind.

I used the below and got what I wanted:

cur_date = date()
start_week = dateadd("d", 1 - weekday(cur_date), cur_date)

So when I do: <%=start_week%> I get 05/04/2008.

I added the same code to another page and it gives me 5/4/2008.

Because I'm posting the info to a varchar field in SQL, I need to keep the format the same. So, what's the trick to getting my original format? I need the leading zero in the single digit months and days.

Thanks!!

 
Old May 11th, 2008, 07:09 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

If I may why post a date into a varchar field?

What if you want to filter your records by date in the SQL, this is such a handy filter. Your client may not want it now however IME they almost always want these type abilities as upgrades

Wind is your friend
Matt
www.elitemarquees.com.au
 
Old May 11th, 2008, 09:12 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Matt,

I can't tell you why the field is a varchar field. All I know is that's what I have to work with because the table already exists.

All I need to know is how to get the leading zeros in there. If there's no simple way, I guess, I could create it.

 
Old May 11th, 2008, 09:33 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

FYI - I asked because IME there is a good chance you may want to get records based on the date value in the future. Having it this way makes your table and the data in it less powerful SQL wise...

I am not aware of any way to append leading zero's to date type values directly. I guess if I had to do it (after strongly suggesting this data type should be changed - all your SQL inserts and updates already have "' & & "' around them. Anyhow enough of that... I would build a function which:

> breaks the date apart (maybe into three variables D, M Y)
> check then len of the D and M
> if len < 1 then append a leading 0
> build string back together

That would be one way to skin your cat


Wind is your friend
Matt
www.elitemarquees.com.au
 
Old May 12th, 2008, 09:27 AM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Matt,

There's already a field with the actual date of the insert. The varchar field for the start of the weeks is for grouping of what was entered during that week.

I still can't figure out how the code works with the zero's in one script, but not the one I'm working on. I've gone over and over the original form that was being used and there's nothing special in it to do the leading zeros.

 
Old May 12th, 2008, 10:15 AM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's what I did to get it to work.

    Function pd(n, totalDigits)
        if totalDigits > len(n) then
            pd = String(totalDigits-len(n),"0") & n
        else
            pd = n
        end if
    End Function

    cur_date = date()

    start_week = dateadd("d", 1 - weekday(cur_date), cur_date)
    start_week = Pd(Month(start_week),2) & "/" & _
        Pd(DAY(start_week),2) & "/" & _
        YEAR(start_week)


 
Old May 12th, 2008, 06:05 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Glad you got it working

;;;I still can't figure out how the code works with the zero's in one script, but not the one I'm working on

My 2 cents worth:

This is one reason global functions are worth thier weight in gold. If you pass a value into one of these provising the syntax of the value is the same there is no reason for a different output. Do both the pages use a global function?
> If so check the syntax of the value being passed into it. From what you say I think it may be different.
> If not create one, you should find your output is the same

Wind is your friend
Matt
www.elitemarquees.com.au





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
Help with date format gregalb SQL Server 2000 1 February 13th, 2007 10:15 AM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM





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