AppleScript returns error on defining date

applescript

my following code returns an error

tell current application
    set b to "Tuesday 12 April 2016 at 18:06:10"
    date b
end tell

If I would write the string, defined in b, directly before date, it is working, but my date string is defined by some variables, so b is just an example for the string, how it looks like.

But why does AppleScript returns the error, only because of the string is defined in a variable?

Best Answer

Try:

set dateString to "Tuesday, April 12, 2016 at 12:00:00 AM"
set dateReference to date dateString

tell current application
    -- insert commands here
end tell

Another approach:

set y to 2001
set m to 6
set d to 12
set h to 12
set min to 12
set s to 12

set cd to current date
tell cd
    set its year to y
    set its month to m
    set its day to d
    set its hours to h
    set its minutes to min
    set its seconds to s
end tell